How can I allow the user to click to check an item in CheckedListBox
in one click? The default behavior is the first click selects the item, the second click allows you to toggle the check. I don't want to toggle the check on select either, I'm looking for the behavior of the ListView
control where I can click directly on check boxes to toggle them without selecting their items first.
The CheckedListBox
has a property CheckOnClick
.
CheckOnClick
indicates whether the check box should be toggled whenever an item is selected. The default behavior is to change the selection on the first click, and then have the user click again to apply the check mark. In some instances, however, you might prefer have the item checked as soon as it is clicked.
Read: How do I CheckOnClick in a CheckedListbox but only when over the checkbox?
I just ran into this problem, and did not find much on Google except the SO question Tim refers to. This sounds like a lot of work for such a basic need, which is a red flag to me. So I guess the problem lies in the design.
In my case I very simply solved it by using a ListView
instead of a CheckedListBox
(changing its properties allows to really get the CheckedListBox
behavior otherwise).
Set the properties like this.
checkedListBox1.SelectionMode = SelectionMode.One;
checkedListBox1.CheckOnClick = true;
And create event in form class.
private void checkedListBox1_MouseUp(object sender, MouseEventArgs e)
{
checkedListBox1.SelectedIndex = -1;
}
© 2022 - 2024 — McMap. All rights reserved.