Vb.net Question

Check the CheckBoxColumn if the Data between two Datagridview Exist

Hello Everyone Good Morning.

I want to ask some Questions but before that let me explain something.

I have 2 Datagridview and this are.

enter image description here

Now you see it, Here is my Question as what you see on both Datagridview there are data the is the same between

Technician Name
and
ElecAssigned
now how can I achieve this?

enter image description here

If the Data in the 2nd Datagridview has the same Data in 1st Datagridview then how the checkbox will checked? If you want to see my code here it is.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con1 As MySqlConnection = New MySqlConnection("datasource=localhost;database=operations;userid=root;password=admin1950;Convert Zero Datetime=True")
Dim sql1 As MySqlCommand = New MySqlCommand("select TechID,TechName from technicians;", con1)
Dim ds1 As DataSet = New DataSet
Dim adapter1 As MySqlDataAdapter = New MySqlDataAdapter
con1.Open()
adapter1.SelectCommand = sql1
adapter1.Fill(ds1, "MyTable")
DataGridView1.DataSource = ds1.Tables(0)
con1.Close()


With DataGridView1
.RowHeadersVisible = False
.Columns(0).HeaderCell.Value = "Technician ID"
.Columns(1).HeaderCell.Value = "Technician Name"

End With
DataGridView1.Columns.Item(0).Width = 60
DataGridView1.Columns.Item(1).Width = 60
DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter
Me.DataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True
Dim checkBoxColumn As New DataGridViewCheckBoxColumn()
checkBoxColumn.HeaderText = "Tag"
checkBoxColumn.Width = 30
checkBoxColumn.Name = "checkBoxColumn"
DataGridView1.Columns.Insert(0, checkBoxColumn)

End Sub



Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim con As MySqlConnection = New MySqlConnection("server=localhost;userid=root;password=admin1950;database=operations")
Dim sql As MySqlCommand = New MySqlCommand("select Distinct ElecAssigned from Assignments", con)
Dim ds As DataSet = New DataSet
Dim adapter As MySqlDataAdapter = New MySqlDataAdapter
con.Open()
adapter.SelectCommand = sql
adapter.Fill(ds, "MyTable")
DataGridView2.DataSource = ds.Tables(0)
con.Close()
end sub


I think it has something to do with this code.

For Each row In DataGridView1.Rows
If DataGridView1.Rows = DataGridView2.Rows Then
Datagridview1.checkBoxColumn.value = True
End If
Next
'Sample Code Only


I hope you get my point TY for the Future Help

I fix it and thanks for the Help
here is the answer

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
For Each row In Me.DataGridView1.Rows
For Each row1 In Me.DataGridView2.Rows
If row.Cells(2).Value.ToString() = (row1.cells(0).Value.ToString()) Then
row.cells(0).value = True
End If
Next
Next

End Sub


'Changes the Row Number

Answer

try this use two diff loops

For Each row In DataGridView1.Rows
   For Each row1 In DataGridView2.Rows
        If rows.Cell[1].Value.ToString().Equals.(rows1.cell[0].Value.ToString()) Then
            row.cell[0].value = True
        End If
    Next

Next