Solved

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

Posted on 2014-12-21
2
457 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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