将选定的行值与另一个行值进行比较
问题描述:
你好,我从gridview中检索了一个单元格值(例如,CustName Peter)(例如grdView)。然后我想将它与gridview中的其余记录(使用循环)进行比较。我该怎么做。任何帮助将不胜感激。
hello, I have retrieved a cell value(eg. CustName Peter) from gridview(eg. grdView). Then I want to compare it with the rest of the records in gridview(using loop). How can I do it. Any help would be appreciated.
答
使用foreach循环
ex :(在VB.Net中)
Use a foreach loop
ex: (in VB.Net)
Dim name As String = "CustName"
Dim columnIndex As Integer = 1
'this is the column index which contains the value to compare
For Each dr As DataGridViewRow In DataGridView1.Rows
If name = dr.Cells.Item(columnIndex).Value Then
'do anything
End If
Next dr
希望这会有所帮助..
问候
Hope this helps..
Regards