DeleteItem

Deletes an item from a ListBox, RibbonComboBoxItem, ListView, TreeView, RibbonMenu, or RibbonBar control.

To delete an item from

Use

A ListBox, DropDownListBox, PictureListBox, DropDownPictureListBox, or RibbonComboBoxItem control

Syntax 1

A ListView control

Syntax 2

A TreeView control

Syntax 3

A RibbonMenu control

Syntax 4

A RibbonBar control

Syntax 5


Syntax 1: For ListBox, DropDownListBox, and RibbonComboBoxItem controls

Description

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

Applies to

ListBox, DropDownListBox, PictureListBox, DropDownPictureListBox, and RibbonComboBoxItem controls

Syntax

listboxname.DeleteItem ( index )

Argument

Description

listboxname

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

index

The position number of the item you want to delete


Return value

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

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))

These statements deletes an item from the ribbon combo box:

Integer li_Return
RibbonComboBoxItem lr_ComboBox

li_Return = lr_ComboBox.SetBoxPictureList("PaperSizeA0Small!,PaperSizeA1Small!")
li_Return = lr_ComboBox.AddItem("Item1")
li_Return = lr_ComboBox.AddItem("Item2",1)
li_Return = lr_ComboBox.DeleteItem(1)

See also

AddItem

FindItem

InsertItem

SelectItem

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


Return value

Integer.

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

Examples

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

AddItem

FindItem

InsertItem

SelectItem

DeleteItems

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


Return value

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

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

See also

AddItem

FindItem

InsertItem

SelectItem

DeleteItems

Syntax 4: For RibbonMenu controls

Description

Removes a menu item from the ribbon menu.

Applies to

RibbonMenu controls

Syntax

controlname.DeleteItem ( { Long ParentIndex, } Long Index )

Argument

Description

controlname

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

ParentIndex (optional)

The index of the menu item (RibbonMenuItem) whose submenu you want to delete.

If not specified, the menu item will be deleted; if specified to a valid value, the submenu of the menu item (whose index is ParentIndex) will be deleted; if specified to an invalid value, an error would occur and this operation would return -1.

Index

The index of the menu item or submenu item you want to delete. If index is invalid, an error would occur and this operation would return -1.

Return value

Integer.

Returns the number of items remaining in the list of values after the item is deleted if it succeeds and -1 if an error occurs. If any argument's value is null, returns null.

Examples

This example inserts a "MenuItem1" menu item and a "SubMenuItem1" submenu item and then deletes them according to their index number.

Long ll_Return,ll_Index,ll_Index2
RibbonMenu lr_Menu
RibbonMenuItem lr_MenuItem1,lr_SubMenuItem1

lr_MenuItem1.Text = "MenuItem1"
lr_SubMenuItem1.Text = "SubMenuItem1"

ll_Index =  lr_Menu.InsertItemLast (lr_MenuItem1)
ll_Index2 = lr_Menu.InsertItemLast (ll_Index,lr_SubMenuItem1)
ll_Return = lr_Menu.DeleteItem (ll_Index,ll_Index2)
ll_Return = lr_Menu.DeleteItem (ll_Index)

See also

AddSeparatorItem

GetItem

GetItemCount

InsertItem

InsertItemFirst

InsertItemLast

SetItem

Syntax 5: For RibbonBar controls

Description

Removes an item from the RibbonBar control.

Applies to

RibbonBar controls

Syntax

controlname.DeleteItem ( Long ItemHandle )

Argument

Description

controlname

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

ItemHandle

The handle of the item which you want to delete.

Return value

Integer.

Returns 1 if it succeeds and -1 if an error occurs. If any argument's value is null, returns null.

Usage

This function can be used to delete items including ApplicationButton, TabButton, Category, Panel, Group, CheckBox, ComboBox, LargeButton, and SmallButton; but cannot delete RibbonMenuItem. To delete RibbonMenuItem, you can use the DeleteItem Syntax 4, DeleteMasterItem, and DeleteRecentItem functions.

You can also use the following functions to delete the individual item control: RemoveApplicationButton, DeleteCategory, DeleteCheckBox, DeleteComboBox, DeleteGroup, DeleteLargeButton, DeletePanel, DeleteSmallButton, and DeleteTabButton.

Examples

This example gets and deletes the categories one by one in a loop. It gets the category by index and deletes it by handle.

Long ll_CateGoryCount, ll_i
Integer li_return
RibbonCategoryItem lr_CateGory

rbb_1.InsertCategoryFirst("MyCategory1")
rbb_1.InsertCategoryLast ("MyCategory2")

//Deletes all categories
ll_CateGoryCount = Rbb_1.GetCateGorycount( )
For ll_i =  ll_CateGoryCount To 1 Step -1
 If rbb_1.getcategoryByIndex( ll_i, lr_CateGory) = 1 Then
  //Deletes a cateogory
  li_return = rbb_1.DeleteItem(lr_Category.itemhandle)
 End If
Next