We help IT Professionals succeed at work.

In VB.Net compare value from  DataGridView and return other value

PNRT asked
Hi experts.   In VB.Net, 2008 and .Net 3.5.  I have a datagridview with 6 columns.   I need to iterate through column 1 and if a match is found to a string, then get the value from the same row but column 2.  An example would be appreciated.  Many Thanks in advance    
Watch Question

you can use findcontrol method of gridview datarow through looping to gridview rows (can aslo be in rowdatabound event ) for that particular value which you want for comparing also and for taking also.

Hope you get what i mean.


Hi, thanks for the reply.  I checked the findcontrol message but cant seem to see the relevance.  Im trying to get the cell value of one cell based on the contents of another cell.   Sorry if I was not clear.
I was looking for something like

for each row in datagridview1
if cell in column 1 = x then same row, column 2 = y

But unfortunately, I wasnt able to get that right.  Is the above not the right way to achive this.
instead of again applying conditional logic better way you can do this in your query itself provided you are binding your datagridview using sql query.

Use Case in sql query.

chk for details: