Cher
Cher

Reputation: 2937

How to edit ListIndex property of a ListBox?

I cannot change directly ListIndex since it's read-only.

After searches, I found this

lstEnergieBatiment.Selected(0) = True

which will highlight it but not select it.

I need the property ListIndex to be edited since depending on user actions, it may be read right after.

How can I achieve this?

This Listbox allow multiple selections.

Upvotes: 0

Views: 1902

Answers (2)

Krish
Krish

Reputation: 5917

I would do like this.

Dim Item As Variant
For Each Item In Me.List.ItemsSelected
    Debug.Print Me.List.ItemData(Item)
Next Item

Upvotes: 0

AcsErno
AcsErno

Reputation: 1615

You can not edit listindex. The system sets listindex to indicate which item is selected by the user. As you handle multiselect, you'd rather use this to see which items are selected:

For i = 0 To LBX.ListCount - 1
    If LBX.Selected(i) Then
    ' whatever

Upvotes: 1

Related Questions