0
votes

How can i compare two datagridview values ? I'm trying to check if Datagridview1 subjectcode is Exist in Datagridview2

EDIT:

It will happen when user click a button. Selected row will be added in datagridview2 list

if datagridview1 subcode  = datagridview2 subcode then
         datagridview1.row color  = gray. 

Datagridview1 ( This is a subject list )

enter image description here

Datagridview2

enter image description here

1
When would you like this to happen? When a user selects a Row? On a Button.Click event? Is it possible that more than one cell has the same value in the second DataGridView? If so, what should happen? - Jimi
@Jimi on button click. Everytime user add the subject in datagridview1 it will go to datagridview2. So if it exist in datagridview2 the color in the datagridview1 row will be gray. Thanks. - Kimberypalet
I think you should add a hidden column in DGV1, containing a boolean value, that you set to True(meaning already copied) when a subject has been added to DGV2. So you can't add it again if this column's value is True. - Jimi

1 Answers

1
votes

You could create a list of subcode from the DataGridView and check it that way.

Dim subCodeList as new List(Of String)

For i as Integer = 0 To datagridview1.Rows.Count - 1
    subCodeList.add(datagridview1.Rows(i).Cells("subCode").Value.toString())
Next

' Then in your second DataGridView
For i as Integer = 0 To datagridview2.Rows.Count - 1
    If subCodeList.Contains(datagridview2.rows(i).cells("subCode").value.tostring()) THEN
       ' Do something if it's found.
    End if

Next

There might be an easier way to do this but this might get you started.