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.

Indexers

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

Properties

NameDescription
countGets the number of elements contained in the collection.

Methods

NameDescription
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.

Examples

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

from api_example_base import ApiExampleBase, ARTIFACTS_DIR

class ExampleFormFields(ApiExampleBase):

    def test_drop_down_item_collection(self):
        doc = aw.Document()
        builder = aw.DocumentBuilder(doc=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'))
        self.assertTrue(drop_down_items.contains('Three'))
        # 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:
        drop_down_items.add('Four')
        # 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 item in drop_down_items:
            print(item)
        # 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:
        drop_down_items.remove('Four')
        # 2 - Remove an item at an index:
        drop_down_items.remove_at(3)
        self.assertEqual(3, drop_down_items.count)
        self.assertFalse(drop_down_items.contains('Three and a half'))
        self.assertFalse(drop_down_items.contains('Four'))
        doc.save(file_name=ARTIFACTS_DIR + 'FormFields.DropDownItemCollection.html')
        # Empty the whole collection of drop-down items.
        drop_down_items.clear()

See Also