G
Guest
I have a TabControl on a Windows form in which I have various tab pages each
with a DataGridView, the first column of which is a
DataGridViewCheckBoxColumn and subsequent columns being
DataGridViewtextBoxColumns.
In each case the properties of the CheckBoxcolumn have been set to not allow
nulls, so presumably only explicit true or false values should be possible.
I run the application and set check boxes for DataGridView rows I am
interested in, in the DataGridViews on any or all of the tab pages.
In code, I use the following in turn on each DataGridView.
foreach (DataGridViewRow r in dgvRange.Rows)
{
if((bool)(r.Cells[0] as DataGridViewCheckBoxCell).Value )
{
//do something
}
}
for the second grid the name changes obviously.
So processing goes from the first, to the second, then the third grid.
Problem is that (bool)(r.Cells[0] as DataGridViewCheckBoxCell).Value part
works on the first grid but not on any subsequent grids even though they are
set identically. The subsequent ones throw an exception as the cast is
invalid.
Despite the DataGridViewCheckBoxColumns being set to not allow nulls for all
the grids, with the exception of the first, the others all evaluate
(r.Cells[0] as DataGridViewCheckBoxCell).Value to null, whilst the first
evaluates to true or false as it should. I do not understand why there
should be any difference. They are unique instances in unique DataGridViews,
and each is configured to not allow nulls so only boolean values should be
possible.
Any ideas would be appreciated.
with a DataGridView, the first column of which is a
DataGridViewCheckBoxColumn and subsequent columns being
DataGridViewtextBoxColumns.
In each case the properties of the CheckBoxcolumn have been set to not allow
nulls, so presumably only explicit true or false values should be possible.
I run the application and set check boxes for DataGridView rows I am
interested in, in the DataGridViews on any or all of the tab pages.
In code, I use the following in turn on each DataGridView.
foreach (DataGridViewRow r in dgvRange.Rows)
{
if((bool)(r.Cells[0] as DataGridViewCheckBoxCell).Value )
{
//do something
}
}
for the second grid the name changes obviously.
So processing goes from the first, to the second, then the third grid.
Problem is that (bool)(r.Cells[0] as DataGridViewCheckBoxCell).Value part
works on the first grid but not on any subsequent grids even though they are
set identically. The subsequent ones throw an exception as the cast is
invalid.
Despite the DataGridViewCheckBoxColumns being set to not allow nulls for all
the grids, with the exception of the first, the others all evaluate
(r.Cells[0] as DataGridViewCheckBoxCell).Value to null, whilst the first
evaluates to true or false as it should. I do not understand why there
should be any difference. They are unique instances in unique DataGridViews,
and each is configured to not allow nulls so only boolean values should be
possible.
Any ideas would be appreciated.