Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

1 solution

Use a foreach loop
ex: (in VB.Net)
VB
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
 
Share this answer
 
v4
Comments
Jamie888 20-Mar-14 3:53am    
thks, but the columnIndex of 1 is the first column or second column?
milindaSnow 20-Mar-14 4:02am    
0 is the first column, 1 is the second column and so on.
Jamie888 20-Mar-14 4:09am    
after I have typed the grdView.Rows, it prompt me the Rows is not a member of Datagrid, what is meant by that?
milindaSnow 20-Mar-14 4:14am    
Check the Updated one, use "dr.Cells.Item(columnIndex).Value" and "dr As DataGridViewRow"
I have tested it.
milindaSnow 20-Mar-14 4:20am    
Hope that works.. let me know if anything happens

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900