SelectedItem Property, SelectedIndex Property (TabStrip)

Purpose

Returns a reference to a selected ListItem, Node, or Tab object.

Syntax

object.SelectedItem [ = item ]

TabStrip.SelectedIndex [ = integer ]

object:TreeView, ListView, TabStrip
item:ListItem, Node, Tab

Description

SelectedItem returns a reference to a selected ListItem, Node, or Tab object, or sets a specified ListItem, Node, or Tab to a selected state.

This property is typically used to return a reference to a ListItem, Node, or Tab or object that the user has clicked or selected. With this reference, you can validate an object before allowing any further action, as demonstrated in the example.

To programmatically select a ListItem object, you can (optionally) use the Set statement with the SelectedItem property, as follows:

Set ListView.SelectedItem = ListView.ListItems(1)

ListView.SelectedItem = ListView.ListItems(1)

GFA-BASIC 32 allows both versions.

The TabStrip control property SelectedIndex returns or sets the Tab object by index (number). See TabStrip_Change event for an example.

Example

Global Int32 n

OpenW 1 : AutoRedraw = 1

Ocx TabStrip tbs = "", 0, 10, TwipsToPixelX(Win_1.Width) - 20, 40

Text 10, 70, "Select: "

Ocx ComboBox cmb = "", 50, 67, 100, 22 : .Sorted = False

For n = 1 To 20 : tbs.Add n, "Key " & Chr(64 + n), "Tab" & n : cmb.AddItem "Tab" & n, n : Next n

cmb.ListIndex = 0

Do : Sleep : Until Win_1 Is Nothing

 

Sub cmb_Click

tbs.Tab(cmb.ItemData(cmb.ListIndex)).Selected = True

EndSub

 

Sub tbs_Change

cmb.ListIndex = tbs.SelectedIndex - 1

Text 10, 90, "Current Key: " & tbs.SelectedItem.Key & "   "

EndSub

See Also

TreeView, ListView, TabStrip, ListItem, Node, Tab

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