These methods are provided for each collection. In addition, these methods exist for each Ocx control that contains a collection.
object.Item( index )
object.Count
object.Clear
object.Remove( index )
object.Add [index], [key], [text], […]
object:Buttons, ListImages, Panels, ListItems, ColumnHeaders, Nodes, Tabs
object:ToolBar, ImageList, StatusBar, ListView, TreeView, TabStrip
index:Variant
These methods and properties exist for the named collections that are a property of Ocx controls. As a shortcut, these properties and methods exist for the Ocx controls themselves as well. For instance, the ToolBar Ocx control contains a Buttons collection of Button objects. The members in the collection can either be accessed through the Buttons collection, but they are also available directly from the ToolBar Ocx. To clear the collection you can invoke the Clear method from Buttons, but also the Clear method from ToolBar; ToolBar.Buttons.Clear is identical to ToolBar.Clear.
Item(index)Specifies the position of a member of the collection. If a numeric expression, index must be a number from 1 to the value of the collection's Count property. If a string expression, index must correspond to the key argument specified when the member referred to was added to the collection. If the value provided as index doesn’t match any existing member of the collection, an error occurs. Item is the default property for a collection. Therefore, the statements are equivalent:
MyCollection(1) MyCollection.Item(1)
Count Returns a Long containing the number of items in a collection. Read-only.
ClearRemoves all objects in a collection.
Remove(index)Removes the specified item from a collection. index specifies the name or index in the collection of the object to be accessed.
AddAdds a member to a collection object. The syntax for the Add method is different for each Ocx collection.
Global li As ListItem, n As Int32
OpenW 1
Ocx ListView lv = "", 10, 10, 200, 300 : .View = 3 : .GridLines = True : .FullRowSelect = True
lv.ColumnHeaders.Add , , "Column1" : lv.ColumnHeaders.Add , , "Column2"
For n = 1 To 20
lv.ListItems.Add , n , "" // Can be shortened to lv.Add ...
lv.ListItems.Item(n).AllText = "Item " & Format(n, "00") & ";" & Chr(64 + n) // Can be shortened to lv(n).AllText ...
Next n
Ocx Command cmd1 = "Remove Selected Item", 220, 10, 140, 22
Ocx Command cmd2 = "Remove all Even Items", 220, 35, 140, 22
Do : Sleep : Until IsNothing(Win_1)
Sub cmd1_Click
If lv.SelectedCount <> 0 // Make sure an item is selected
Set li = lv.SelectedItem
lv.ListItems.Remove li.Index
EndIf
EndSub
Sub cmd2_Click
Static Int32 cycle = 1
Select cycle
Case 1 // Remove Even
For n = lv.ListItems.Count DownTo 1
Set li = lv.ListItems(n) : Debug li.Key
If Even(Val(li.Key)) = True Then lv.ListItems.Remove li.Index
Next n
cmd2.Caption = "Delete remaining Items"
Case 2
lv.ListItems.Clear
EndSelect
Inc cycle
EndSub
GFA-BASIC 32 supports the following Ocx collections: Buttons, ListImages, Panels, ColumnHeaders, ListItems, Nodes, and Tabs.
Buttons, ListImages, Panels, ColumnHeaders, ListItems, Nodes, Tabs
ToolBar, ImageList, StatusBar, ListView, TreeView, TabStrip
{Created by Sjouke Hamstra; Last updated: 11/10/2014 by James Gaite}