?
Solved

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

Posted on 2014-12-21
2
Medium Priority
?
513 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
Michael Fowler earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

762 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