CheckedListBox state to property
-
Can you directly store the CheckState.Checked / Unchecked value in a class property? If so how would you store it, or do I have to examine it and store a bool? Thanks.
I don't think so, but you can attach a handler for the ItemCheck event.
-
Can you directly store the CheckState.Checked / Unchecked value in a class property? If so how would you store it, or do I have to examine it and store a bool? Thanks.
-
If you need to track the checked items in the control, you can make use of
CheckedIndices
property.50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
So you cannot store the e.CheckState value in the ItemCheck event? I have many collections to display/redisplay in the same checkedlistbox. I would rather push a value to the object in the list when it is checked then cycle through all of them before changing the collection being displayed. I have
if (e.NewValue == CheckState.Checked)
dv.checkedInLB = true;
else
dv.checkedInLB = false;which works fine, but adds a step.
-
So you cannot store the e.CheckState value in the ItemCheck event? I have many collections to display/redisplay in the same checkedlistbox. I would rather push a value to the object in the list when it is checked then cycle through all of them before changing the collection being displayed. I have
if (e.NewValue == CheckState.Checked)
dv.checkedInLB = true;
else
dv.checkedInLB = false;which works fine, but adds a step.
I haven't tried it, but I would expect something like:
((SomeType)checkedListBox1.SelectedItem).checkedInLB = e.NewValue == CheckState.Checked ;
-
So you cannot store the e.CheckState value in the ItemCheck event? I have many collections to display/redisplay in the same checkedlistbox. I would rather push a value to the object in the list when it is checked then cycle through all of them before changing the collection being displayed. I have
if (e.NewValue == CheckState.Checked)
dv.checkedInLB = true;
else
dv.checkedInLB = false;which works fine, but adds a step.
If you keep the checked state in some other property, you will be checking that then. So any ways you will have to check by some mean or the another that check box is checked or not. Am I understanding your problem correct or not? I assume you want to store checkedstate in a boolean property. Like:
if (checkedListBox.Items[index].checked){
// do something
}
else{
// do something else
}50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!