Solved

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

Posted on 2014-12-21
2
442 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
Comment Utility
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
Comment Utility
Thank you
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

15 Experts available now in Live!

Get 1:1 Help Now