AddItem

Adds an item to a list control.

To add an item to

Use

A ListBox or DropDownListBox control

Syntax 1 For ListBox and DropDownListBox controls

A PictureListBox or DropDownPictureListBox control

Syntax 2 For PictureListBox controls

A ListView control when you only need to specify the item name and picture index

Syntax 3 For ListView controls

A ListView control when you need to specify all the properties for the item

Syntax 4 For ListView controls

A toolbar item to the Toolbar control

Syntax 5 For Toolbar controls


Syntax 1 For ListBox and DropDownListBox controls

Description

Adds a new item to the list of values in a list box.

Applies to

ListBox and DropDownListBox controls

Syntax

listboxname.AddItem ( item )

Argument

Description

listboxname

The name of the ListBox or DropDownListBox in which you want to add an item

item

A string whose value is the text of the item you want to add

Returns

Integer. Returns the position of the new item. If the list is sorted, the position returned is the position of the item after the list is sorted. Returns -1 if it fails. If any argument’s value is null, AddItem returns null.

Usage

If the ListBox already contains items, AddItem adds the new item to the end of the list. If the list is sorted (its Sorted property is true), PocketBuilder re-sorts the list after the item is added.

A list can have duplicate items. Items in the list are tracked by their position in the list, not their text.

AddItem and InsertItem do not update the Items property array. You can use FindItem to find items added during execution.

NoteAdding many items to a list with a horizontal scrollbar If a ListBox or the ListBox portion of a DropDownListBox will have a large number of items and you want to display an HScrollBar, call the SetRedraw function to turn Redraw off, add the items, call SetRedraw again to set Redraw on, and then set the HScrollBar property to true. Otherwise, it may take longer than expected to add the items.

Examples

Example 1

This example adds the item Edit File to the ListBox lb_Actions:

integer rownbr

string s


s = "Edit File"

rownbr = lb_Actions.AddItem(s)

If lb_Actions contains Add and Run and the Sorted property is false, the statement above returns 3 (because Edit File becomes the third and last item). If the Sorted property is true, the statement above returns 2 (because Edit File becomes the second item after the list is sorted alphabetically).

See also


Syntax 2 For PictureListBox controls

Description

Adds a new item to the list of values in a picture list box.

Applies to

PictureListBox controls

Syntax

listboxname.AddItem ( item {, pictureindex } )

Argument

Description

listboxname

The name of the PictureListBox in which you want to add an item

item

A string whose value is the text of the item you want to add

pictureindex (optional)

An integer specifying the index of the picture you want to associate with the newly added item

Returns

Integer. Returns the position of the new item. If the list is sorted, the position returned is the position of the item after the list is sorted. Returns -1 if it fails. If any argument’s value is null, AddItem returns null.

Usage

If you do not specify a picture index, the newly added item will not have a picture.

If you specify a picture index that does not exist, that number is still stored with the picture. If you add pictures to the picture array so that the index becomes valid, the item will then show the corresponding picture.

For additional notes about items in list boxes, see Syntax 1.

Examples

Example 2

This example adds the item Cardinal to the PictureListBox plb_birds:

integer li_pic, li_position

string ls_name, ls_pic


li_pic = plb_birds.AddPicture("c:\pics\cardinal.bmp")

ls_name = "Cardinal"

li_position = plb_birds.AddItem(ls_name, li_pic)

If plb_birds contains Robin and Swallow and the Sorted property is false, the AddItem function above returns 3 because Cardinal becomes the third and last item. If the Sorted property is true, AddItem returns 1 because Cardinal is first when the list is sorted alphabetically.

See also


Syntax 3 For ListView controls

Description

Adds an item to a ListView control.

Applies to

ListView controls

Syntax

listviewname.AddItem ( label, pictureindex )

Argument

Description

listviewname

The name of the ListView control to which you are adding a picture or item

label

The name of the item you are adding

pictureindex

The index of the picture you want to associate with the newly added item

Returns

Integer. Returns the index of the item if it succeeds and -1 if an error occurs.

Usage

Use this syntax if you only need to specify the label and picture index of the item you are adding to the ListView. If you need to specify more than the label and picture index, use Syntax 4.

Examples

Example 3

This example uses AddItem in the Constructor event to add three items to a ListView control:

lv_1.AddItem("Sanyo" , 1)

lv_1.AddItem("Onkyo" , 1)

lv_1.AddItem("Aiwa" , 1)

See also


Syntax 4 For ListView controls

Description

Adds an item to a ListView control by referencing all the attributes in the ListView item.

Applies to

ListView controls

Syntax

listviewname.AddItem ( item )

Argument

Description

listviewname

The name of the List View control to which you are adding a picture or item

item

The ListViewItem variable containing properties of the item you are adding

Returns

Integer. Returns the index of the item if it succeeds and -1 if an error occurs.

Usage

Use this syntax if you need to specify all the properties for the item you want to add. If you only need to specify the label and picture index, use Syntax 3.

Examples

Example 4

This example uses AddItem in a CommandButton Clicked event to add a ListView item for each click:

count = count + 1
listviewitem l_lvi
l_lvi.PictureIndex = 2
l_lvi.Label = "Item "+ string(count)
lv_1.AddItem(l_lvi)

See also


Syntax 5 For Toolbar controls

Description

Adds a toolbar item to the toolbar control.

Applies to

Toolbar controls

Syntax

Integer controlname.AddItem ( item )

Argument

Description

controlname

The name of the toolbar control

item

Object of type ToolbarItem that you want to add to the toolbar

Returns

Integer. Returns the index of the item that you add to the toolbar.

Examples

Example 5

The following example adds two toolbar items to the next available positions in the toolbar:

Integer li_rtn

ToolbarItem myItem

myItem.ItemPictureIndex = 1

myItem.ItemStyle = stylecheck!

li_rtn = tlbr_mytoolbar.AddItem(myItem)

myItem.ItemPictureIndex = 2

myItem.ItemStyle = stylebutton!

li_rtn = tlbr_mytoolbar.AddItem(myItem)

See also