GetItem

Retrieves data associated with a specified item in ListView and TreeView controls.

To retrieve data associated with a specified

Use

ListView control item

Syntax 1 For ListView controls

ListView control item and column

Syntax 2 For ListView controls

TreeView item

Syntax 3 For TreeView controls


Syntax 1 For ListView controls

Description

Retrieves a ListViewItem object from a ListView control so you can examine its properties.

Applies to

ListView controls

Syntax

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

Returns

Integer. Returns 1 if it succeeds and -1 if an error occurs. Stores a ListViewItem object in a ListViewItem variable.

Usage

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.

Examples

Example 1

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)

See also


Syntax 2 For ListView controls

Description

Retrieves the value displayed for a ListView item in a specified column.

Applies to

ListView controls

Syntax

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.

Returns

Integer. Returns 1 if it succeeds and -1 if an error occurs. Stores the displayed value of the ListView column in a string variable.

Usage

To retrieve property values for a ListView item, use Syntax 1.

Examples

Example 2

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 + "."

See also


Syntax 3 For TreeView controls

Description

Retrieves the data associated with the specified item.

Applies to

TreeView controls

Syntax

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

Returns

Integer. Returns 1 if it succeeds and -1 if an error occurs.

Usage

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.

Examples

Example 3

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)

See also