473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 57237
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Laurent | last post by:
I have got a three state checkbox, where i would like to apply a readonly properties in order to keepthe three state view (Check and Blank, Unchecked and Blank, Checked and shaded) when my...
1
by: PontiMax | last post by:
Hi, is there any ASP.NET checkbox control that supports the three states 'Off', 'On' and 'Mixed'? I intend to build a tree whose checkbox nodes are set to state 'Mixed' if some but not all child...
3
by: Woody Splawn | last post by:
I have a winform with a checkbox on it. The editor is named CBXE30. I have it bound to a bit field in SQL Server 2000. In design mode, in the databindings section of the control I have the...
6
by: James Black | last post by:
'When my form is submitted, I have onsubmit pointed to the following code snippet. But, the button is not actually set to disabled and the style.visibility changes are not made for several...
4
by: jojoba | last post by:
hello all, does anyone know if, for a 2-state checkbox, you can use the "fill in" marker from the 3-state checkbox, instead of a checkmark i just like the look of the "fill-in" instead of the...
7
by: schaefty | last post by:
I recently posted this on the incorrect forum, and so I would like to ask the question here. I did get some good ideas on the other group, but I have not yet come up with a solution for me. I am...
2
by: kenny.love | last post by:
I have a form (Form1) with a combo box (Combo43) with three values: Reference 1 Antenatal 1 Quant 1 I also have two check boxes (check36 and check34) What is the best way to implement such...
4
by: _Who | last post by:
I have a master containing radio buttons all with the same group name. If I select one of the buttons and then navigate to a different page the buttons revert to their initial state. Is that...
0
by: Chocolade | last post by:
I created a new form and added split container and then on the left side a treeview and on the treeview i added nodes and on the right side of the split container i added a groupbox. Now in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.