See Also Example
Adds a new item to a list box or combo box or adds a new row to a grid control at run time.
Syntax.
control.AddItem item [,index]
Remarks
The AddItem method has these parts:
Part Description
control List box, combo box, or grid control.
item String expression to add to the control. For grid controls only, use the tab character (character code 09) to separate multiple strings you want inserted into each column of a newly added row.
index Integer representing the position within the control where the new item or row is placed. For the first item in a list box or combo box, or for the first row in a grid control, index = 0.
AddItem places item in the list box, combo box, or grid specified by control. If you supply a valid value for the optional index, item is placed at that position within the control. If index is omitted, item is added at the proper sorted position (if Sorted property is True), or to the end of the list (if Sorted is False).
Clear Method
RemoveItem Method
The example uses AddItem to add 100 items to a list box. To try this example, paste the code into the Declarations section of a form with a list box control named List1. Then press F5 and click the form.
Sub Form_Click ()
Dim Entry, I, Msg ' Declare variables
Msg = "Choose OK to add 100 items to your list box."
MsgBox Msg ' Display message.
For I = 1 To 100 ' Count from 1 to 100.
Entry = "Entry " & I ' Create entry.
List1.AddItem Entry ' Add the entry.
Next I
Msg = "Choose OK to remove every other entry."
MsgBox Msg ' Display message.
For I = 1 To 50 ' Determine how to
List1.RemoveItem I ' remove every other
Next I ' item.
Msg = "Choose OK to remove all items from the list box."
MsgBox Msg ' Display message.
List1.Clear ' Clear list box.
End Sub