title | keywords | f1_keywords | api_name | ms.assetid | ms.date | ms.localizationpriority | ||
---|---|---|---|---|---|---|---|---|
WebListBoxItems.AddItem method (Publisher) |
vbapb10.chm4128772 |
|
|
1c3af4d1-ed0b-60c6-b607-17712612cec2 |
06/18/2019 |
medium |
Adds list items to a web list box control.
expression.AddItem (Item, Index, SelectState, ItemValue)
expression A variable that represents a WebListBoxItems object.
Name | Required/Optional | Data type | Description |
---|---|---|---|
Item | Required | String | The name of the item as it appears in the list. |
Index | Optional | Long | The number of the list item. If Index is not specified or if it is out of range of the indices of existing list box items, the new item is added to the end of the list box. Otherwise, the new item is inserted at the position specified by Index, and the index position of all the items after it are increased by one. |
SelectState | Optional | Boolean | True if the item is selected when the list box is initially displayed. The default value is False. |
ItemValue | Optional | String | The value of the list box item. If not specified, the new item's value is the same as the item name. |
When you programmatically create a new web list box, it contains three items. Use the Delete method to remove them from the list.
This example creates a new list box control in the active publication, removes the three default list items, and then adds several items to it.
Sub AddListBoxItems()
Dim intCount As Integer
With ActiveDocument.Pages(1).Shapes.AddWebControl _
(Type:=pbWebControlListBox, Left:=100, _
Top:=100, Width:=150, Height:=100)
With .WebListBox.ListBoxItems
For intCount = 1 To .Count
.Delete (1)
Next
.AddItem Item:="Green"
.AddItem Item:="Yellow"
.AddItem Item:="Red"
.AddItem Item:="Blue"
.AddItem Item:="Purple"
.AddItem Item:="Chartreuse"
.AddItem Item:="Pink"
.AddItem Item:="Olive"
End With
End With
End Sub
[!includeSupport and feedback]