Programmatically checking a DataGridViewCheckboxCell

  • Thread starter Thread starter CJM
  • Start date Start date
C

CJM

I can't for the life of me figure out how to check or uncheck a cell
programmatically. I've looked in Lutz's reflector to see how the
control is doing it and it calling an UpdateButtonState method that I
don't have access to.

This must be super simple but I'm just missing something.

Any help would be GREATLY appreciated :)
 
Hi,

If the DataGridView is data-bound just set the value in the associated property or column of your data source to "true".
 
I can't for the life of me figure out how to check or uncheck a cell
programmatically. I've looked in Lutz's reflector to see how the
control is doing it and it calling an UpdateButtonState method that I
don't have access to.

This must be super simple but I'm just missing something.

public Form1()
{
InitializeComponent();
this.dataGridView1.Rows.Add();
}

private void button1_Click( object sender, EventArgs e )
{
bool value = (bool)( this.dataGridView1.Rows[0].Cells[0].Value ?? false );
this.dataGridView1.Rows[0].Cells[0].Value = !value;
}
 
Back
Top