I don't know how it will perform in the end, but you can easily use Linq as well. Place this code in e.g. the CellEndEdit event:
BtnCancel.Enabled = dataGridView1.Rows
.Cast<DataGridViewRow>()
.Select(a => a.Cells[0].Value as bool?)
.Count(a => a.HasValue && a.Value) > 0;
First the rows are casted as an IEnumerable<datagridviewrow> allowing the subsequent
.Select
to allow selecting the
.Cells
property of the row. Then select the first cell and cast its value as
bool?
. When the cell checkbox is checked its value is
True
, but when it is unchecked it returns
null
. Next
.Count
all cells that have a value and with value is
True
.
When the count of these cells > 0, the
BtnCancel.Enabled
is
True
.
You need to tweak it of course for your use case, but this should work. Also be aware that I did not test this for performance, but at the time this runs slow, you might need to consider refactoring anyhow :)