Is there a way to make some of the items in a ListBox readonly/disabled so they can't be selected? Or are there any similar controls to ListBox to provide this functionality?
相关问题
- How do I bind a DataGridViewComboBoxColumn to a pr
- Partial Form Class C# - Only display code view for
- Can we add four protocols to ServicePointManager.S
- How to properly handle form closing when using bac
- Filter Datagridview rows using TextBox
相关文章
- Sort TreeView Automatically Upon Adding Nodes
- Where does this quality loss on Images come from?
- Missing partial modifier on declaration of type
- PropertyGrid - Possible to have a file/directory s
- Why do base Windows Forms form class with generic
- How to handle the TextChanged event only when the
- Difference between SuspendLayout and BeginUpdate
- Adding Combobox to DataGridView Headers
ListBox doesn't have support for that. You can bolt something on, you could deselect a selected item. Here's a silly example that prevents even-numbered items from being selected:
But the flicker is quite noticeable and it messes up keyboard navigation. You can get better results by using CheckedListBox, you can prevent the user from checking the box for an item:
But now you cannot override drawing to make it look obvious to the user that the item isn't selectable. No great solutions here, it is far simpler to just not display items in the box that shouldn't be selectable.
@Hans solution causing that the item id selected for a short time and then selection disappearing. I don't like that - this can be confusing for the enduser.
I prefer to hide some edit option buttons for the item that should be disabled:
Here is the list that lists the users and disallow to edit user that is actually logged in to the edit panel.
ListBox
doesn't have aReadOnly
(or similar) property, but you can make a customListBox
control. Here's a solution that worked pretty well for me:https://ajeethtechnotes.blogspot.com/2009/02/readonly-listbox.html
I know this is old thread, but i'll post a workaround for other readers in future.
This will change background color of list box to Light Gray. So this is not builtin "native way" to do it, but at least gives user some feedback that he is not supposed to / can't edit that field.