Check item in CheckedListBox without selecting
Asked Answered
K

3

7

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.

Koniology answered 30/4, 2010 at 12:42 Comment(0)
C
20

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?

Cachepot answered 30/4, 2010 at 13:8 Comment(3)
But then when I click on the text of an item, not the check box, it checks/unchecks itself. This is not the behaviour of the ListView. I want to be able to check the boxes independently of selecting items.Koniology
I have edited my answer and added a link: seems that somebody had already the same requirement on stackoverflow.comCachepot
Interesting, thanks. It's strange that it's not implemented in the control by default.Koniology
L
1

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).

Labile answered 28/5, 2012 at 9:54 Comment(1)
This is probably the correct answer to the original question. The CheckedListBox control is actually too limited and simply does not allow to "check the boxes independently of selecting items" like the original poster would like.Paunchy
R
0

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;
    }
Rowen answered 9/9, 2022 at 15:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.