Rowdyone52
asked on
Checkbox count DataGridView
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?
ASKER
How do I access the checkbox inside of the datagridview??
ASKER
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?
datagridview1[0,ROW].value
What event lets me know that the checkbox value has changed so that I may recalculate?
sorry, i forgot to add this.
//This will find the control inside tthe datagridview
CheckBox chkBox = (CheckBox)dataGridView1.Co ntrols["ch eckbox1"];
//This will set the event in the CheckBox
chkBox.CheckedChanged = checkBox1.CheckedChanged += new EventHandler(checkBox1_Che ckedChange d);
//This will find the control inside tthe datagridview
CheckBox chkBox = (CheckBox)dataGridView1.Co
//This will set the event in the CheckBox
chkBox.CheckedChanged = checkBox1.CheckedChanged += new EventHandler(checkBox1_Che
ASKER
Ok im still a little lost. Where in the program do I define chkBox?
Does (CheckBox)dataGridView1.Co ntrols["ch eckbox1"] give me access when the checkbox is clicked on any row?
Does (CheckBox)dataGridView1.Co
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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_Che
protected void checkBox1_CheckedChanged(o
{
//If the checkbox is true increment else decrement.
LabelCount.Text = ((CheckBox)sender).Checked
(Convert.ToInt32(LabelCoun
}
Regards
Rodrigo Leote