FullRowSelect, MultiSelect Properties, and SelectedCount, SelectedItems Methods (ListView)

Purpose

Returns or sets a value that determines if checkboxes appear, the number of boxes checked, and a collection of selected items.

Syntax

ListView.FullRowSelect [ = Boolean ]

ListView.MultiSelect [ = Boolean ]

ListView.SelectedCount

ListView.SelectedItems

object: ListView, TreeView

Description

FullRowSelect returns or sets a value that specifies if the entire row is selected. This property is only valid when the View property is set to lvwReport (3).

MultiSelect returns or sets a value indicating whether a user can select multiple objects or items. (Pressing SHIFT and clicking the mouse or pressing SHIFT and one of the arrow keys (UP ARROW, DOWN ARROW, LEFT ARROW, and RIGHT ARROW) extends the selection from the previously selected ListItem to the current ListItem. Pressing CTRL and clicking the mouse selects or deselects a ListItem in the list.)

The SelectedCount property returns the number of selected list items.

SelectedItems returns a reference to a ListItems collection containing all selected items.

Example

Global a$, m As Int, n As Int

Dim li As ListItem

Ocx ListView lv1 = , 10, 10, 500, 150 : lv1.View = 3

Ocx Label lbl1 = "Selected Lines: 0", 10, 170, 100, 14 : lbl1.BackColor = RGB(255, 255, 255)

Ocx Label lbl2 = "Selected Items:", 10, 185, 100, 14 : lbl2.BackColor = RGB(255, 255, 255)

Ocx TextBox tx = "", 10, 200, 100, 200 : tx.BorderStyle = 1 : tx.MultiLine = True

For n = 1 To 5 : lv1.ColumnHeaders.Add , , "Column" & n : Next n

For n = 1 To 5 :

a$ = "" : For m = 1 To 5 : a$ = a$ & "Item " & ((n - 1) * 5) + m & Iif(m <> 5, ";", "") : Next m

lv1.Add , , "" : lv1(n).AllText = a$

Next n

lv1.FullRowSelect = True

lv1.MultiSelect = True

Do : Sleep : Until Me Is Nothing

 

Sub lv1_Click

lbl1.Caption = "Selected Lines: " & lv1.SelectedCount

tx.Text = ""

For Each li In lv1.SelectedItems

a$ = li.AllText

For n = 1 To 5 : m = InStr(a$, ";") : If m = 0 Then m = Len(a$) + 1

tx.Text = tx.Text & Left(a$, m - 1) & #13#10 : a$ = Mid(a$, m + 1)

Next n

Next

EndSub

Remarks

SelectedCount is equivalent to SelectedItems.Count.

SelectedItem is used in conjunction with BeforeLabelEdit event.

See Also

ListView, ListItems, ListItem

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