Solved

Checkbox count DataGridView

Posted on 2007-03-29
6
1,684 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
  • 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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 500 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
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…

759 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

19 Experts available now in Live!

Get 1:1 Help Now