Solved

How to get if my gridview control's checkbox cell is checked?

Posted on 2014-12-21
2
450 Views
Last Modified: 2014-12-21
Hi, I'm using VS2012.
In the row updating event, I need to see if user checked the checkbox.  In the gridview, 1st column is the auto generated Edit.  4 columns to the right is my checkbox column.  What index should I use, 4?  (edit button is 1?)  and code like this?
 dt.Rows[row.DataItemIndex]["IsComplete"] = ((CheckBox)(row.Cells[4].Controls[0])).Checked;

Also, what is the Controls[0]?  What index is it referring to with 0?

Thank you.
0
Comment
Question by:lapucca
2 Comments
 
LVL 23

Accepted Solution

by:
Michael74 earned 500 total points
ID: 40511985
If this is a checkbox column the value to check is TrueValue/FalseValue
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcheckboxcell(v=vs.110).aspx

so use something like

DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)row.Cells[4].Value
if (cell.Value == cell.FalseValue || cell.Value == null)
            {
                // Action if false
            }
            else
            {
                //Action if true;
            }

Open in new window


Not sure where you got your code from but I would guess in this case that this is the zero based collection of controls in the cell and since the only only control in the cell is the check box you call index 0 to get this checkbox.
0
 

Author Closing Comment

by:lapucca
ID: 40512010
Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now