I can recommend using a
BindingSource
, see
A Detailed Data Binding Tutorial
A Detailed Data Binding Tutorial[
^]
To get or set the value:
private void DataGridView1CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
switch (this.DataGridView1.Columns[e.ColumnIndex].Name)
{
case "Absence":
bool flag = (bool)this.DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
this.DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value = !flag;
break;
case "vacation":
bool flag = (bool)this.DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
this.DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex - 1].Value = !flag;
break;
}
}