InsertItemFirst

Inserts an item as the first child of a parent item.

To insert an item as the first child of its parent

Use

When you only need to specify the item label and picture index

Syntax 1

When you need to specify more than the item label and picture index

Syntax 2

RibbonMenu control

Syntax 3


Syntax 1: For TreeView controls

Description

Inserts an item as the first child of its parent.

Applies to

TreeView controls

Syntax

treeviewname.InsertItemFirst ( handleparent, label, pictureindex )

Argument

Description

treeviewname

The TreeView control in which you want to specify an item as the first child of its parent.

handleparent

The handle of the item that will be the inserted item's parent. To insert the item at the first level, specify 0.

label

The label of the item you want to specify as the first child of its parent.

pictureindex

The picture index for the item you want to specify as the first child of its parent.


Return value

Long.

Returns the handle of the item inserted if it succeeds and -1 if an error occurs.

Examples

This example populates the first level of a TreeView using InsertItemFirst:

long ll_lev1, ll_lev2 ,ll_lev3 ,ll_lev4
int index
tv_list.PictureHeight = 32
tv_list.PictureWidth = 32
ll_lev1 = tv_list.InsertItemFirst(0,"Composers",1)
ll_lev2 = tv_list.InsertItemLast(ll_lev1, &
    "Beethoven",2)
ll_lev3 = tv_list.InsertItemLast(ll_lev2, &
    "Symphonies", 3)
FOR index = 1 to 9
    ll_lev4 = tv_list.InsertItemSort(ll_lev3, &
      "Symphony # " + String(index) , 4)
NEXT
tv_list.ExpandItem(ll_lev3)
tv_list.ExpandItem(ll_lev4)

See also

InsertItem

InsertItemLast

InsertItemSort

Syntax 2: For TreeView controls

Description

Inserts an item as the first child of an item.

Applies to

TreeView controls

Syntax

treeviewname.InsertItemFirst ( handleparent, item )

Argument

Description

treeviewname

The TreeView control in which you want to specify an item as the first child of its parent.

handleparent

The handle of the item that will be the inserted item's parent. To insert the item at the first level, specify 0.

item

A TreeViewItem structure for the item you are inserting.


Return value

Long.

Returns the handle of the item inserted if it succeeds and -1 if an error occurs.

Usage

If SortType is anything except Unsorted!, items are sorted after they are added and the TreeView is always in a sorted state. Therefore, calling InsertItemFirst, InsertItemLast, and InsertItemSort produces the same result.

Examples

This example inserts the current item as the first item beneath the root item in a TreeView control:

long          ll_handle, ll_roothandle
treeviewitem  l_tvi
ll_handle = tv_list.FindItem(CurrentTreeItem!, 0)
ll_roothandle = tv_list.FindItem(RootTreeItem!, 0)
tv_list.GetItem(ll_handle , l_tvi)
 
tv_list.InsertItemFirst(ll_roothandle, l_tvi)

See also

InsertItem

InsertItemLast

InsertItemSort

Syntax 3: For RibbonMenu controls

Description

Inserts a menu item as the first item in a ribbon menu.

Applies to

RibbonMenu controls

Syntax

controlname.InsertItemFirst ( { Long ParentIndex, } String Text, String PictureName, String Clicked )
controlname.InsertItemFirst ( { Long ParentIndex, } RibbonMenuItem Item )

Argument

Description

controlname

The RibbonMenu control into which you want to insert a menu item as the first item.

ParentIndex

The index of the menu item (RibbonMenuItem) into which you want to insert a submenu item.

It cannot be an index of a separator (that is RibbonMenuItem with ItemType 1). If not specified, a menu item will be inserted as the first item; if specified to a valid value, a submenu item will be inserted as the first item under the menu item (whose index is ParentIndex); if specified to an invalid value, an error would occur and this operation would return -1.

Text

The text that displays in the menu item or submenu item.

PictureName

The name of the file that contains the picture. The image will be displayed in 16*16 pixels.

Clicked

The name of the Clicked user event to be bound with the menu item. The Clicked user event for the menu item must be defined with the required parameters and types. For details, see Clicked.

Item

A RibbonMenuItem item you want to insert. Only RibbonMenuItem with "Normal(0)" or "Separator(1)" ItemType is supported. If RibbonMenuItem is with other ItemType such as "Recent(2)", an error would occur and this operation would return -1.


Return value

Long.

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

Usage

Only menu items with the "Normal" or "Separator" type (that is RibbonMenuItem with ItemType 0 or 1) can be added to the RibbonMenu control.

A RibbonMenu control can contain menu items in no more than two levels.

The user events to be bound with the menu item must be defined correctly according to the requirements of RibbonMenuItem. For details, see Clicked and Selected.

Example 1

This example inserts a "MenuItem1" menu item as the first item and then inserts two submenu items under "MenuItem1" in the following display order: "SubMenuItem1", "SubMenuItem2".

Long ll_Return,ll_Index
RibbonMenu lr_Menu

ll_Index =  lr_Menu.InsertItemFirst("MenuItem1","AddSmall!","Ue_MenuItem1Clicked")
ll_Return =  lr_Menu.InsertItemFirst(ll_Index,"SubMenuItem2","AddSmall!","Ue_MenuItem12Clicked")
ll_Return =  lr_Menu.InsertItemFirst(ll_Index,"SubMenuItem1","AddSmall!","Ue_MenuItem11Clicked")

Example 2

This example also inserts a "MenuItem1" menu item as the first item and then inserts two submenu items under "MenuItem1" in the following display order: "SubMenuItem1", "SubMenuItem2". It first defines three RibbonMenu items (lr_MenuItem1, lr_SubMenuItem1, lr_SubMenuItem2) with various properties (including binding with the "Ue_MenuItem1Clicked" and "Ue_MenuItem1Selected" user events), and then inserts lr_MenuItem1 as the first menu item "MenuItem1", and inserts the other two as the submenu items under "MenuItem1" in the following display order: "SubMenuItem1", "SubMenuItem2".

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

lr_MenuItem1.Text = "MenuItem1"
lr_MenuItem1.PictureName = "AddSmall!"
lr_MenuItem1.Clicked = "Ue_MenuItem1Clicked"
lr_MenuItem1.Selected = "Ue_MenuItem1Selected"
lr_SubMenuItem1.Text = "SubMenuItem1"
lr_SubMenuItem2.Text = "SubMenuItem2"

ll_Index =  lr_Menu.InsertItemFirst(lr_MenuItem1)
ll_Return =  lr_Menu.InsertItemFirst(ll_Index,lr_SubMenuItem2)
ll_Return =  lr_Menu.InsertItemFirst(ll_Index,lr_SubMenuItem1)

See also

AddSeparatorItem

DeleteItem

GetItem

GetItemCount

InsertItem

InsertItemLast

SetItem