Home > Language Reference > Classes > ChoiceControl

AddItem Method

Adds an item to a list.

Syntax

Public Sub AddItem(ByVal sValue As String, Optional ByVal lData As Long = 0)

ParameterDescription
sValueElement value.
lDataValue defined by the programmer.

Remarks

The AddItem method adds an item to the list displayed by the control. The sValue argument is the text that will be displayed whilst the optional lData argument allows you to associate a value of type Long with this new element for use in your program. This last value can be retrieve later using the ItemData.

If the Sorted property is set to hbSortNone, the element is added to the end of the list. Otherwise, it is inserted into the list in accordance with the sort option specified. In both cases, the position where the element is inserted can be found using the NewIndex method.

By default, the control is redrawn on each insertion. If you are inserting several elements consecutively, it is recommended to temporarily set the Redraw property to False, in order to improve the performance of your program and prevent the control from flickering.

The text specified by the sValue argument cannot contain special characters such as carriage returns or tabs. If it is wider than the width of the control, it is truncated on the right.

The example below fills a list with the numbers from 0 to 9:

Private Sub Button1_Click()
  Dim i as Integer

  List1.Redraw = False
  List1.Clear
  For i = 0 To 9
    List1.AddItem "Item #" & CStr(i)
  Next i
  List1.Redraw = True
End Sub

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0N/A