Home All Groups Group Topic Archive Search About

Programmatically checking a DataGridViewCheckboxCell

Author
28 Sep 2006 10:36 PM
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 :)

Author
29 Sep 2006 1:56 AM
Dave Sexton
Hi,

If the DataGridView is data-bound just set the value in the associated property or column of your data source to "true".

--
Dave Sexton

Show quote
"CJM" <cjmarq***@yahoo.com> wrote in message news:1159482979.135726.86310@m73g2000cwd.googlegroups.com...
>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 :)
>
Author
30 Sep 2006 11:26 PM
Tim Van Wassenhove
On 2006-09-28, CJM <cjmarq***@yahoo.com> wrote:
> 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;
}


--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>

AddThis Social Bookmark Button