Acting on an indeterminate checkbox checkstate
-
I'm setting up a search and I want the user to be able to decide if they want to see results based on a particular state of a boolean column in the table or ignore it and retrieve all rows regardless of the boolean state. (I hope that makes sense) Essentially I want the user to be able to set a checkbox as checked, unchecked, or indeterminate and have my program act on any three of these states. Is it possible to catch an indeterminate checkstate? If so, how? As far as I can tell, both checked and indeterminate return a true checked value, so I can't use null, and there is no checkstate value for indeterminate. Help! (Thanks in advance! Any help or advice would be tremendously appreciated!)
-
I'm setting up a search and I want the user to be able to decide if they want to see results based on a particular state of a boolean column in the table or ignore it and retrieve all rows regardless of the boolean state. (I hope that makes sense) Essentially I want the user to be able to set a checkbox as checked, unchecked, or indeterminate and have my program act on any three of these states. Is it possible to catch an indeterminate checkstate? If so, how? As far as I can tell, both checked and indeterminate return a true checked value, so I can't use null, and there is no checkstate value for indeterminate. Help! (Thanks in advance! Any help or advice would be tremendously appreciated!)
Check the CheckState property (no pun intended!).
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) -
Check the CheckState property (no pun intended!).
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) -
Can you elaborate? It sounds as though you're telling me to do what I've already tried. I need a different action for all three checkstates: checked, unchecked and indeterminate.
Set the CheckBoxes ThreeState property to true, then use a switch to determine the search scope.
switch (checkBox1.CheckState)
{
case CheckState.Checked:
// do your thing
break;
case CheckState.Indeterminate:
// do some other thing
break;
default: // Unchecked
// do the Hokey Cokey
break;
}If you want the action to take place when the CheckBox is clicked, use the CheckStateChanged event, not the CheckedChanged as the latter doesn't respond to Indeterminate.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) -
Set the CheckBoxes ThreeState property to true, then use a switch to determine the search scope.
switch (checkBox1.CheckState)
{
case CheckState.Checked:
// do your thing
break;
case CheckState.Indeterminate:
// do some other thing
break;
default: // Unchecked
// do the Hokey Cokey
break;
}If you want the action to take place when the CheckBox is clicked, use the CheckStateChanged event, not the CheckedChanged as the latter doesn't respond to Indeterminate.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) -
Hm... That's interesting. Does this only work in a switch statement? I was trying to use an if statement with no success. Thank you for your help, Davey.
If statements will work fine
if (checkBox1.CheckState == CheckState.Checked)
{
//
}
else if (checkBox1.CheckState == CheckState.Indeterminate)
{
//
}
else
{
//
}Lodeclaw wrote:
Thank you for your help
No problem :)
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)