MultiSelect, Selected Properties (ListBox, ListView)

Purpose

MultiSelect returns or sets a Boolean value indicating whether a user can make multiple selections in a ListBox. The Selected property returns or sets the selection status of an item in a ListBox control.

Syntax

object.MultiSelect [= boolean]

object.Selected(index) [= boolean]

object:ListBox, ListView

Description

The Selected() property is an array of Boolean values with the same number of items as the List property.

Example

Form frm = "Listbox", , , 500, 400

Ocx ListBox lb1 "", 0, 0, 250, 200

.MultiSelect = 1

.TabStop = True

Ocx ListBox lb2 = "", 250, 0, 250, 200

.TabStop = True

Ocx Command cmd1 = "Add to 2", 100, 220, 80, 24

cmd1.Enabled = False

Dim i%

For i = 0 To Screen.FontCount - 1

lb1.AddItem Screen.Fonts(i)

Next i

lb1.SetFocus

Do

Sleep

Until Me Is Nothing

 

Sub cmd1_Click ()

Dim i%

lb2.Clear       ' Clear all items from the list.

For i = 0 To lb1.ListCount - 1

If lb1.Selected(i) Then

lb2.AddItem lb1.List(i)

End If

Next i

End Sub

 

Sub lb1_Click

' The missing ListBox property: SelCount:

Dim SelCount% = SendMessage(lb1.hWnd, LB_GETSELCOUNT, 0, 0)

If SelCount = 0 && cmd1.Enabled

cmd1.Enabled = False

Else If SelCount > 0 && cmd1.Enabled = False

cmd1.Enabled = True

EndIf

EndSub

See Also

ListBox, ListView

{Created by Sjouke Hamstra; Last updated: 20/10/2014 by James Gaite}