Looping through a datagrid
-
Hi, I know its last thing on a Friday but I hope someone can help. I need to loop through every cell in a datagridview and make sure that each value is not null. Looping through the cells isn't a problem (I don't think), I used a for loop with another nested inside, the inner loop taking care of the column index and the outer loop holding the row index. What I can't do is check the contents of each cell as there is no suitable method in DataGridCell. Please can anyone help? Thanks Scott The loop code used if anyone is interested. for (int i = 0; i <= rowCount; i++) { for (int j = 0; j <= colCount; j++) { DataGridCell dgc = new DataGridCell(i, j); } } Scott
-
Hi, I know its last thing on a Friday but I hope someone can help. I need to loop through every cell in a datagridview and make sure that each value is not null. Looping through the cells isn't a problem (I don't think), I used a for loop with another nested inside, the inner loop taking care of the column index and the outer loop holding the row index. What I can't do is check the contents of each cell as there is no suitable method in DataGridCell. Please can anyone help? Thanks Scott The loop code used if anyone is interested. for (int i = 0; i <= rowCount; i++) { for (int j = 0; j <= colCount; j++) { DataGridCell dgc = new DataGridCell(i, j); } } Scott
Are you looking for something like this... grvMain.Rows[0].Cells[1].Text; I hope this helps. I have worked quited a bit with gridviews so let me know if I misunderstood your question. If you have controls you are attempting to check in the cells it should look more like this... ((TextBox)GridView1.Rows[1].FindControl("txtProviderID")).Text. Regards