Deletes an item from a ListBox, DropDownListBox, or ListView control.
To delete an item from |
Use |
---|---|
A ListBox or DropDownListBox control |
|
A ListView control |
|
A TreeView control |
Deletes an item from the list of values for a list box control.
ListBox, DropDownListBox, PictureListBox, and DropDownPictureListBox controls
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 |
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.
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.
Assuming lb_actions contains 10 items, this statement deletes item 5 from lb_actions and returns 9:
lb_actions.DeleteItem(5)
These statements delete the first selected item in lb_actions:
integer li_Index
li_Index = lb_actions.SelectedIndex()
lb_actions.DeleteItem(li_Index)
This statement deletes the item "Personal" from the ListBox lb_purpose:
lb_purpose.DeleteItem( &
lb_purpose.FindItem("Personal", 1))
Deletes the specified item from a ListView control.
ListView controls
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 |
Integer. Returns 1 if it succeeds and -1 if an error occurs.
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)
Deletes an item from a control and all its child items, if any.
TreeView controls
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 |
Integer. Returns 1 if it succeeds and -1 if an error occurs.
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.
This example deletes an item from a TreeView control:
long ll_tvi
ll_tvi = tv_list.FindItem(CurrentTreeItem!, 0)
tv_list.DeleteItem(ll_tvi)
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