How to check if datagrid cell exists?

I have an if condition:

if (e.Item.Cells[7].Text == "something") 

But how can I first check if cell [7] exists?

Thanks...

+4
source share
1 answer

You can use the Cells.Count property. If it is greater than 7, then Cells[7] exists (since the index is based on zero).

 if (e.Item.Cells.Count > 7 && e.Item.Cells[7].Text == "something") 
+7
source

All Articles