Get DataGridView checkbox cell value?
Posted
by George
on Stack Overflow
See other posts from Stack Overflow
or by George
Published on 2010-01-24T20:04:01Z
Indexed on
2010/04/16
13:03 UTC
Read the original article
Hit count: 236
c#
|datagridview
Hello guys.
I'm having a strange issue here.
I have a 3 column datagrid that is filled by a connection with the database. So far so good.
I have an extra column, of checkbox type. I need to get it's value for perfoming a bulk operation on it. Here is the catch:
When all cells are selected, it works fine. But when an user selects any cell that its not the first, software gives me a object reference exception.
Here is the code
public List<String> GetSelected()
{
List<String> selected = new List<String>();
foreach(DataGridViewRow row in datagrid.rows)
{
if ((Boolean)row.Cells[wantedCell].Value == true)
{
selected.Add(row.Cells[anotherCell]);
}
}
}
I tracked down the failure to the if-test, throwing a exception, because the value of the cell is read as null.
Any thougths?
Thanks
© Stack Overflow or respective owner