简体   繁体   中英

How to compare two datagridview row cell value?

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 )

在此处输入图片说明

Datagridview2

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM