Hi,
For unbound column, you’d better set the default value in DataGridView_DefaultValueNeed event.
void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
e.Row.Cells["checkColumn"].Value = true;
}
Or set the DefaultCellStyle.NullValue.
chkcolumn.DefaultCellStyle.NullValue = true;
Then you can get the true value by
dataGridView1.CurrentRow.Cells["checkColumn"].FormattedValue
The following example shows binding datagridview to a datatable, add checkboxColumn to the datagridview.
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt01 = new DataTable("dt01");
dt01.Columns.Add("col01");
dt01.Columns.Add("col02");
dt01.Columns.Add("col03");
dt01.Rows.Add("aa", "11", "a1");
dt01.Rows.Add("aa", "11", "a1");
dt01.Rows.Add("aa", "11", "a1");
dataGridView1.DataSource = dt01;
DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();
chk.Name = "Check";
chk.HeaderText = "Test";
chk.DefaultCellStyle.NullValue = true;
dataGridView1.Columns.Add(chk);
}
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.CurrentRow.Cells["Check"].Value = false;
}
Best regards,
Ling Wang
Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.