Sorted, TopIndex Properties (ComboBox, ListBox, ListView)

Purpose

Sorted returns a value indicating whether the elements of a ComboBox and ListBox are automatically sorted alphabetically.

TopIndex returns or sets a value that specifies which item in a ComboBox, ListBox, or a ListView control is displayed in the topmost position.

Syntax

object.Sorted [= boolean]

object.TopIndex [= value]

object:ListBox, ComboBox, ListView, TreeView

Description

ComboBox and ListBox

When Sorted is True, GFA-BASIC 32 handles almost all necessary string processing to maintain alphabetic order, including changing the index numbers for items as required by the addition or removal of items. Using the InsertItem method to add an element to a specific location in the list may violate the sort order, and subsequent additions may not be correctly sorted.

TopIndex = value sets the number of the list item that is displayed in the topmost position. The default is 0, or the first item in the list.

If the Columns property is set to 0 for the ListBox control, the item is displayed at the topmost position if there are enough items below it to fill the visible portion of the list. If the Columns property setting is greater than 0 for the ListBox control, the item's column moves to the leftmost position without changing its position within the column.

ListView

For a ListView control the TopIndex property is read-only and returns the number of the topmost ListItem.

Example

Global Int32 n

AutoRedraw = 1

Ocx ListBox lb = "", 10, 10, 100, 200 : lb.Sorted = False

For n = 40 DownTo 1 : lb.AddItem "Item " & Format(n, "00") : Next n

Ocx TextBox tb = "", 120, 10, 40, 14 : .BorderStyle = 1 : .ReadOnly = True : Text 170, 11, "ListBox TopIndex Value"

Ocx UpDown up : .BuddyControl = tb : .Min = 0 : .Max = 40 : .Increment = 1 : .Value = lb.TopIndex

Ocx CheckBox chk = "Sort ListBox Entries", 120, 30, 120, 14

Do : Sleep : Until Me Is Nothing

 

Sub chk_Click

Local ti As Int32 = lb.TopIndex

lb.Sorted = -chk.Value

For n = 40 DownTo 1 : lb.AddItem "Item " & Format(n, "00") : Next n

lb.TopIndex = ti

EndSub

 

Sub up_Change

lb.TopIndex = up.Value

EndSub

See Also

ListBox, ComboBox, ListView, ListItem

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