DeleteItem

Deletes an item from a ListBox, DropDownListBox, or ListView control.

To delete an item from

Use

A ListBox or DropDownListBox control

Syntax 1 For ListBox and DropDownListBox controls

A ListView control

Syntax 2 For ListView controls

A TreeView control

Syntax 3 For TreeView controls


Syntax 1 For ListBox and DropDownListBox controls

Description

Deletes an item from the list of values for a list box control.

Applies to

ListBox, DropDownListBox, PictureListBox, and DropDownPictureListBox controls

Syntax

listboxname.DeleteItem ( index )

Argument

Description

listboxname

The name of the ListBox, DropDownListBox, PictureListBox, or DropDownPictureListBox from which you want to delete an item

index

The position number of the item you want to delete

Returns

Integer. Returns the number of items remaining in the list of values after the item is deleted. If an error occurs, DeleteItem returns -1. If any argument’s value is null, DeleteItem returns null.

Usage

If the control’s Sorted property is set, the order of the list is probably different from the order you specified when you defined the control. If you know the item’s text, use FindItem to determine the item’s index.

Examples

Example 1

Assuming lb_actions contains 10 items, this statement deletes item 5 from lb_actions and returns 9:

lb_actions.DeleteItem(5)

Example 2

These statements delete the first selected item in lb_actions:

integer li_Index

li_Index = lb_actions.SelectedIndex()

lb_actions.DeleteItem(li_Index)

Example 3

This statement deletes the item "Personal" from the ListBox lb_purpose:

lb_purpose.DeleteItem( &

    lb_purpose.FindItem("Personal", 1))

See also


Syntax 2 For ListView controls

Description

Deletes the specified item from a ListView control.

Applies to

ListView controls

Syntax

listviewname.DeleteItem ( index )

Argument

Description

listviewname

The name of the ListView control from which you want to delete an item

index

The index number of the item you want to delete

Returns

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

Examples

Example 4

This example uses SelectedIndex to find the index of the selected ListView item and then deletes the corresponding item:

integer index

index = lv_list.selectedindex()

lv_list.DeleteItem(index)

See also


Syntax 3 For TreeView controls

Description

Deletes an item from a control and all its child items, if any.

Applies to

TreeView controls

Syntax

treeviewname.DeleteItem ( itemhandle )

Argument

Description

treeviewname

The name of the TreeView control from which you want to delete an item

itemhandle

The handle of the item you want to delete

Returns

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

Usage

If all items are children of a single item at the root level, you can delete all items in the TreeView with the handle for RootTreeItem as the argument for DeleteItem. Otherwise, you need to loop through the items at the first level.

Examples

Example 5

This example deletes an item from a TreeView control:

long ll_tvi

ll_tvi = tv_list.FindItem(CurrentTreeItem!, 0)

tv_list.DeleteItem(ll_tvi)

Example 6

This example deletes all items from a TreeView control when there are several items at the first level:

long tvi_hdl = 0

DO UNTIL tv_1.FindItem(RootTreeItem!, 0) = -1

    tv_1.DeleteItem(tvi_hdl)

LOOP

See also