Link to home
Create AccountLog in
Avatar of aarcia
aarcia

asked on

How can I disable items in a windows checkbox list control?

I am developing a small Windows application in VB.NET 2003. I need to show a check box list control and disable some of its items, Could you teach me how can I disable an item in the list.

Thanks a lot for you help.
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

There isn't any way that I know of to disable an item in the CheckedListBox control.  I would suggest instead of disabling, that you should just remove that item.

Bob
You could also catch the ItemCheck event and, if the item is one that should be checked, uncheck the item. That way the user could never check the items you don't want them to check, but they would still be displayed. You could also pop up a MessageBox informing the user that the item isn't available.
Avatar of aarcia
aarcia

ASKER

The solution provided for TheLearnedOne is what I am doing at this moment. I was looking for a way to show the forbidden items with gray font to simulate like if the item were disable.

Thanks a lot for your help.
Avatar of aarcia

ASKER

As TheLEarnedOne says, I need a solutoin for a window application.

Thanks a lot.

I am trying to find an article I read some time before about how to acomplish this requirement. Of course, in that moment I was looking for other thing, then I did not save the article nor I don't remember where. I just remember that they was talking about to overwrite the draw item event. In this event you can set the font and the background color for each item. Then you could grey the avoided items. So, In the Item_Check event, uncheck any avoided item. Even more, they talked about disable the keyboard key correspoding to the first letter of the avoided item when the you got focus in the control.

Thank a lot.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Sample usage:

    Me.CheckedBoxListEx1.DisabledItems.Add(0)

Bob