Search code examples
powershelllistboxlistboxitem

PowerShell System.Windows.Forms disable a certain items in ListBox


Is there a way to disable a few items in the System.Windows.Forms.ListBox in PowerShell?

i.e. ListBox contains:

item-a
item-b
item-c
item-d
item-e

and I like to make for example, item-c and item-e not selectable. Thanks!


Solution

  • Short answer: There is no native Disable/Enable items in the ListBox control.

    I see two ways to do it:

    1. Have an array of items that you don't want selectable. When handling your click event, check to see if the item is one that you don't want selected, and do nothing.
    2. The easier method: Create a custom control. See: How to Disable Selected Item in List Box