views:

178

answers:

2

How do I find a cell with a specific content in a DataGridView?

+4  A: 

I dont know of a way to find a cell by content so you'll have to iterate through the cells and look for the value you need. You can use the .FindControl() method to find actual controls (label, literal, checkbox, etc) inside cells or go through them by index GridView.Rows.Cells[index]

Edit: This answer will work on an ASP.NET page (tested) and should work in a winform (untested)

Ariel
+2  A: 

Ariel is right on, you will have to iterate through the GridViewRowCollection and then each cell of the individual GridViewRow, you can get the cell's text property or like Ariel mentioned if it is a control use FindControl and extract the appropriate property

RandomNoob