Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15556

VS 2019 [RESOLVED] Help! updating DGV cells with values from another DGV

$
0
0
Hello!

Please I need some help, I've been scratching my head for a while trying to figure out this...
I want to update some DGV cells with the values from another DGV cells, all this on the Load event of my form, something like this:

Name:  2a.jpg
Views: 11104
Size:  41.1 KB

I can manually update specific cells on a DGV, my problem is... I don't know how to do this automatically.

OK, I have 2 DGVs:
DataGridView2: (the one at the top) it has no bindings, it is just populated at run time.
DataGridView1: (the one at the bottom) it is bound to a database table.

DataGridView2 is populated with the following code (No problem here!):
VB.NET Code:
  1. DataGridView2.Columns.Add(0, "Horario")
  2.             Dim I As Integer
  3.             For Each item As String In ComboBox4.Items 'get the column names from this ComboBox
  4.                 DataGridView2.Columns.Add(I, item)
  5.                 I += 1
  6.             Next
  7.  Dim limite As Integer
  8.             Dim StartTime As TimeSpan = TimeSpan.Parse("08:00") 'starts shift
  9.             Dim EndTime As TimeSpan = TimeSpan.Parse("17:00") 'Ends shift
  10.             Dim duration = EndTime - StartTime
  11.             Dim durationInmins = duration.TotalMinutes
  12.             limite = Math.Abs(durationInmins) / 10
  13.  
  14.             'Generates the time values on column [Horario]
  15.             Dim temp As Date = #01/01/0001 08:00#
  16.             Dim starter As Date = temp
  17.             starter = starter.AddMinutes(-10)
  18.             Dim minu As Double = 10.0
  19.             For s As Integer = 0 To limite
  20.                 starter = starter.AddMinutes(minu)
  21.                 DataGridView2.Rows.Add(starter.ToShortTimeString())
  22.             Next

My attempt to update the cell values on DataGridView2:
VB.NET Code:
  1. For Each col As DataGridViewColumn In DataGridView2.Columns
  2.                 For Each row As DataGridViewRow In DataGridView1.Rows
  3.                     Dim time_row As String = row.Cells("Horario_Inicia").Value
  4.                     If row.Cells("Barbero").Value = "Max" Then
  5.                         DataGridView2.Item(2, 2).Value = (row.Cells("Barbero").Value) '(Col, row)
  6.                     Else
  7.                         DataGridView2.Rows.Add()
  8.                     End If
  9.                 Next
  10.             Next

Please, I'll appreciate any help!
Attached Images
 

Viewing all articles
Browse latest Browse all 15556

Trending Articles