469,268 Members | 920 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,268 developers. It's quick & easy.

DataGridViewCheckBoxColumn - change the state of a checkbox

I have an unbound DataGridView with a DataGridViewCheckBoxColumn as column
2(configured in the designer). How would I programatically set the checkbox
state in, say, row 3 column 2?

I need to do this in two contexts. One is to make Checked the default in
this column when rows are created (the RowsAdded event might help me here,
although I suspect not for the first row). The other context is to
check/uncheck a checkbox in an existing row.

As you might guess I am new to this. Any help greatly appreciated.

Thanks

Bill.
Dec 19 '05 #1
6 56742
Hi Bill,

To set the checkbox value in DataGridView programatically, you can set the
value of that cell directly. For example, you need to set the checkbox
Checked in row 3 col 2, you can use

this.dataGridView1.Rows[3].Cells[2].Value = true;

As far as I know, we cannot set the default value for the column in the
DataGridView if it is not unbound. Have to set the value for that column in
each row added with a line of code like above.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Dec 20 '05 #2
Thank so much. It works.

-- Bill.

"Kevin Yu [MSFT]" wrote:
Hi Bill,

To set the checkbox value in DataGridView programatically, you can set the
value of that cell directly. For example, you need to set the checkbox
Checked in row 3 col 2, you can use

this.dataGridView1.Rows[3].Cells[2].Value = true;

As far as I know, we cannot set the default value for the column in the
DataGridView if it is not unbound. Have to set the value for that column in
each row added with a line of code like above.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Dec 20 '05 #3
You're welcome.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Dec 20 '05 #4
i think that's only for web form... how bout how to set the checkbox in a
winform? i cant seem to set the state to be a checked checkbox.. pls help thnx

"Kevin Yu [MSFT]" wrote:
Hi Bill,

To set the checkbox value in DataGridView programatically, you can set the
value of that cell directly. For example, you need to set the checkbox
Checked in row 3 col 2, you can use

this.dataGridView1.Rows[3].Cells[2].Value = true;

As far as I know, we cannot set the default value for the column in the
DataGridView if it is not unbound. Have to set the value for that column in
each row added with a line of code like above.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 21 '06 #5

You should set TrueValue = True and FalseValue = False.

"Dave" wrote:
Actually it does work as I navigate through the source data and show
different stuff in the grid, and I can go back to the origianl databinding at
that works too, it seems to just be the initial data that doesn't have the
checkboxes checking?!?!!?
Jul 4 '07 #6
i'm having teh same issue :( anyone know what might be happening? i'm
setting the value of the cell as with the webform example above, but in
winform, doesn't seem to work. i can set the value, and retrieve it, but the
GUI doesn't reflect the changes. i believe my TrueValue and FalseValue are
set up correctly as well...anyone know what i may be missing?

Thanks!

"Ejay" wrote:
i think that's only for web form... how bout how to set the checkbox in a
winform? i cant seem to set the state to be a checked checkbox.. pls help thnx

"Kevin Yu [MSFT]" wrote:
Hi Bill,

To set the checkbox value in DataGridView programatically, you can set the
value of that cell directly. For example, you need to set the checkbox
Checked in row 3 col 2, you can use

this.dataGridView1.Rows[3].Cells[2].Value = true;

As far as I know, we cannot set the default value for the column in the
DataGridView if it is not unbound. Have to set the value for that column in
each row added with a line of code like above.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
Mar 18 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by PontiMax | last post: by
3 posts views Thread by Woody Splawn | last post: by
7 posts views Thread by schaefty | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.