Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

DataGridViewCheckBoxColumn - change the state of a checkbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill - 19 Dec 2005 23:33 GMT
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.
Kevin Yu [MSFT] - 20 Dec 2005 03:45 GMT
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
Signature

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

Bill - 20 Dec 2005 03:58 GMT
Thank so much. It works.

-- Bill.

> Hi Bill,
>
[quoted text clipped - 14 lines]
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
Kevin Yu [MSFT] - 20 Dec 2005 08:44 GMT
You're welcome.

Kevin Yu
Signature

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

Ejay - 21 Feb 2006 20:34 GMT
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

> Hi Bill,
>
[quoted text clipped - 14 lines]
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
Gene Valgene - 18 Mar 2008 05:48 GMT
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!

> 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
[quoted text clipped - 17 lines]
> > "This posting is provided "AS IS" with no warranties, and confers no
> > rights."

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.