Programmatically uncheck checkboxcolumn in datagridview

Awesome picture Awesome · Jan 18, 2011 · Viewed 26.3k times · Source

How can I programmatically uncheck all rows in a DataGridViewCheckboxColumn in a datagridview?

I can get the correct value of the checkbox using

(bool)row.Cells[CheckBoxColumn.Index].FormattedValue

but that's only a getter.

I have tried setting the value of the cell using

(bool)row.Cells[CheckBoxColumn.Index].value = false

but that doesn't affect the FormattedValue.

How can I solve this?

Answer

basti picture basti · Jan 18, 2011

You do sth. like:

(row.Cells[CheckBoxColumn.Index] as DataGridViewCheckBoxCell).value = false;

You just forgot to cast to the correct type, a generic DataGridViewCell doesn't know its value-type.