Problem: Need to toggle all cells in a DataGridViewCheckBoxColumn. We’re using a dynamically generated set of checkbox columns starting after two static columns.
private void dataGridView1_ColumnHeaderMouseClick(object sender,
int colNumber = e.ColumnIndex;
if (colNumber > ROLE_COLUMN_START_POSITION)
bool selectAll = (bool) dataGridView1.Rows.Cells[colNumber].FormattedValue;
foreach (DataGridViewRow row in dataGridView1.Rows)
row.Cells[colNumber].Value = !selectAll;
Adapted from a couple Google hits. Yes, it’s based off the value already extant in row one, but hey, it’s just ducky.
(Thanks to Kramer for getting the grid built and populated in short order today!) (Now I wish he’d just start blogging so he could write this stuff himself.)