Retrieves data associated with a specified item in ListView, TreeView, and Toolbar controls.
To retrieve data associated with a specified |
Use |
---|---|
ListView control item |
|
ListView control item and column |
|
TreeView item |
|
Toolbar control item |
Retrieves a ListViewItem object from a ListView control so you can examine its properties.
ListView controls
listviewname.GetItem ( index, {column}, item )
Argument |
Description |
---|---|
listviewname |
The name of the ListView control for which you want to retrieve the ListView item |
index |
The index number of the item you want to retrieve |
column |
The index number of the column for which you want item information |
item |
The ListViewItem variable in which you want to store the ListViewItem object |
Integer. Returns 1 if it succeeds and -1 if an error occurs. Stores a ListViewItem object in a ListViewItem variable.
You can retrieve properties for any ListView item with this syntax. If you do not specify a column, GetItem retrieves properties for the first column of an item. Only report views display multiple columns.
To retrieve labels only, use syntax 2. You can use GetColumn to obtain column properties that are not specific to a ListView item.
To change pictures and other property values associated with a ListView item, use GetItem, change the property values, and use SetItem to apply the changes back to the ListView.
This example uses GetItem to move the second item in the lv_list ListView control to the fifth item. It retrieves item 2, inserts it into the ListView control as item 5, and then deletes the original item:
listviewitem l_lvi
lv_list.GetItem(2, l_lvi)
lv_list.InsertItem(5, l_lvi)
lv_list.DeleteItem(2)
Retrieves the value displayed for a ListView item in a specified column.
ListView controls
listviewname.GetItem ( index, column, label )
Argument |
Description |
---|---|
listviewname |
The name of the ListView control from which you want to retrieve a displayed value. |
index |
The index number of the item for which you want to retrieve a displayed value. |
column |
The index number of the column for which you want to retrieve a value. If the ListView is not a multicolumn report view, all the items are considered to be in column 1. |
label |
A string variable in which you store the displayed value. |
Integer. Returns 1 if it succeeds and -1 if an error occurs. Stores the displayed value of the ListView column in a string variable.
To retrieve property values for a ListView item, use Syntax 1.
This example gets the displayed values from column 1 and column 3 of the first row of the lv_list ListView and displays them in the sle_info SingleLineEdit control.
string ls_artist, ls_comp
lv_list.GetItem(1, 1 , ls_comp)
lv_list.GetItem(1, 3 , ls_artist)
sle_info.text = ls_artist +" wrote " + ls_comp + "."
Retrieves the data associated with the specified item.
TreeView controls
treeviewname.GetItem ( itemhandle, item)
Argument |
Description |
---|---|
treeviewname |
The name of the TreeView control in which you want to get data for a specified item |
itemhandle |
The handle for the item for which you want to retrieve information |
item |
A TreeViewItem variable in which you want to store the item identified by the item handle |
Integer. Returns 1 if it succeeds and -1 if an error occurs.
Use GetItem to retrieve the state information associated with a specific item in a TreeView (such as label, handle, or picture index). After you have retrieved the information, you can use it in your application. To change a property of an item, call GetItem to assign the item to a TreeViewItem variable, change its properties, and call SetItem to copy the changes back to the TreeView.
This code for the Clicked event gets the clicked item and changes it overlay picture. The SetItem function copies the change back to the TreeView:
treeviewitem tvi
This.SetItem(handle, tvi)
tvi.OverlayPictureIndex = 1
This.SetItem(handle, tvi)
This example tracks items in the SelectionChanged event. If there is no prior selection, the value of l_tviold is zero:
treeviewitem l_tvinew, l_tviold
// Get the treeview item that was the old selection
tv_list.GetItem(oldhandle, l_tviold)
// Get the treeview item that is currently selected
tv_list.GetItem(newhandle, l_tvinew)
// Print the labels for the two items in the
// SingleLineEdit
sle_get.Text = "Selection changed from " &
+ String(l_tviold.Label) + " to " &
+ String(l_tvinew.Label)
Gets a reference to an item in the toolbar.
Toolbar controls
Integer controlname.GetItem ( toolbarindex, item )
Argument |
Description |
---|---|
controlname |
The name of the toolbar control |
toolbarindex |
Integer for the index of the toolbar item |
item |
Reference to a ToolbarItem object |
Integer. Returns 1 for success and -1 if an error occurs.
The following example passes a reference to the second item in the toolbar:
Integer li_rtn
ToolbarItem myItem
myItem = CREATE ToolbarItem
li_rtn = tlbr_mytoolbar.GetItem(2, myItem)