DropDownItemCollection class

A collection of strings that represent all the items in a drop-down form field. To learn more, visit the Working with Fields documentation article.


__getitem__(index)Gets or sets the element at the specified index.


countGets the number of elements contained in the collection.


add(value)Adds a string to the end of the collection.
clear()Removes all elements from the collection.
contains(value)Determines whether the collection contains the specified value.
index_of(value)Returns the zero-based index of the specified value in the collection.
insert(index, value)Inserts a string into the collection at the specified index.
remove(name)Removes the specified value from the collection.
remove_at(index)Removes a value at the specified index.


Shows how to insert a combo box field, and edit the elements in its item collection.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)
# Insert a combo box, and then verify its collection of drop-down items.
# In Microsoft Word, the user will click the combo box,
# and then choose one of the items of text in the collection to display.
items = ['One', 'Two', 'Three']
combo_box_field = builder.insert_combo_box('DropDown', items, 0)
drop_down_items = combo_box_field.drop_down_items
self.assertEqual(3, drop_down_items.count)
self.assertEqual('One', drop_down_items[0])
self.assertEqual(1, drop_down_items.index_of('Two'))
# There are two ways of adding a new item to an existing collection of drop-down box items.
# 1 -  Append an item to the end of the collection:
# 2 -  Insert an item before another item at a specified index:
drop_down_items.insert(3, 'Three and a half')
self.assertEqual(5, drop_down_items.count)
# Iterate over the collection and print every element.
for drop_down in drop_down_items:
# There are two ways of removing elements from a collection of drop-down items.
# 1 -  Remove an item with contents equal to the passed string:
# 2 -  Remove an item at an index:
self.assertEqual(3, drop_down_items.count)
self.assertFalse(drop_down_items.contains('Three and a half'))
doc.save(ARTIFACTS_DIR + 'FormFields.drop_down_item_collection.html')
# Empty the whole collection of drop-down items.

See Also