Multi Select List Box

后端 未结 4 1800
名媛妹妹
名媛妹妹 2021-01-03 09:41

I have a list box on a form and it works fine for what I want to do.

I am wanting to edit items on the form, this means populating the listbox and then selecting the

4条回答
  •  一整个雨季
    2021-01-03 10:24

    You have to change the ListBox.SelectionMode property in order to enable multiple-selection.
    The possible values are given by the SelectionMode enum, as follows:

    None: No items can be selected
    One: Only one item can be selected
    MultiSimple: Multiple items can be selected
    MultiExtended: Multiple items can be selected, and the user can use the Shift, Ctrl, and arrow keys to make selections


    So, you simply need to add the following line to the code you already have:

    ' Change the selection mode (you could also use MultiExtended here)
    lstItemSizes.SelectionMode = SelectionMode.MultiSimple;
    
    ' Select any items of your choice
    lstItemSizes.SetSelected(1, True)
    lstItemSizes.SetSelected(3, True)
    lstItemSizes.SetSelected(8, True)
    

    Alternatively, you can set the SelectionMode property at design time, instead of doing it with code.

提交回复
热议问题