Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Checkbox count DataGridView

Posted on 2007-03-29
6
Medium Priority
?
1,698 Views
Last Modified: 2008-01-09
I need to count the number of checkboxes that are checked in a datagridview control.  so basically column 0 is a checkbox field, and if someone checks a box I need to show 1 box checked in a label control.  How can I accomplish this?
0
Comment
Question by:Rowdyone52
[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
  • 3
  • 3
6 Comments
 
LVL 4

Expert Comment

by:Neotk
ID: 18819522
Yoo man!
you can do this:

in your checkbox inside the datagridview, you must set the event to increment your label count if is true
or decrement if it's false;

checkbox1.CheckedChanged = checkBox1.CheckedChanged += new EventHandler(checkBox1_CheckedChanged);

protected void checkBox1_CheckedChanged(object sender, EventArgs e)
{
  //If the checkbox is true increment else decrement.
   LabelCount.Text = ((CheckBox)sender).Checked ? (Convert.ToInt32(LabelCount.Text) + 1).ToString() :
                                                             (Convert.ToInt32(LabelCount.Text) - 1).ToString() :
}

Regards
Rodrigo Leote
0
 

Author Comment

by:Rowdyone52
ID: 18819654
How do I access the checkbox inside of the datagridview??
0
 

Author Comment

by:Rowdyone52
ID: 18819734
I access the checkboxes value by using
datagridview1[0,ROW].value

What event lets me know that the checkbox value has changed so that I may recalculate?
0
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!

 
LVL 4

Expert Comment

by:Neotk
ID: 18819765
sorry, i forgot to add this.

//This will find the control inside tthe datagridview
CheckBox chkBox =  (CheckBox)dataGridView1.Controls["checkbox1"];

//This will set the event in the CheckBox
chkBox.CheckedChanged = checkBox1.CheckedChanged += new EventHandler(checkBox1_CheckedChanged);

0
 

Author Comment

by:Rowdyone52
ID: 18820040
Ok im still a little lost.  Where in the program do I define chkBox?  

Does (CheckBox)dataGridView1.Controls["checkbox1"] give me access when the checkbox is clicked on any row?

0
 
LVL 4

Accepted Solution

by:
Neotk earned 2000 total points
ID: 18821115
Look, now i'm not at work, i can explain it better.

when you use this command: (CheckBox)dataGridView1.Controls["checkbox1"],
you are searching the control that is inside the dataGridView1 (this is the name example for your datagridview, but if you changed the default name, you have to use the datagridview instance name that you are using) and the name is "checkbox1", here if your checkbox have a different name you should put your checkbox name here. the "(CheckBox)" is just doing the cast of the Control to type "CheckBox.

the CheckBox chkBox is refering to the just found checkbox inside the datagridview.

chkBox.CheckedChanged = checkBox1.CheckedChanged += new EventHandler(checkBox1_CheckedChanged);

this will set the event to your checkbox inside your datagridview. So, everytime you click it, it'll fire the event that sets in the label the counter.

you must define the chkBox in your Load wherever.

Sorry because its a little hard to explain.

Regards
Rodrigo Leote.
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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!
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 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