SdtListItemCollection class

SdtListItemCollection class

Provides access to SdtListItem elements of a structured document tag. To learn more, visit the Structured Document Tags or Content Control documentation article.

Indexers

NameDescription
__getitem__(index)Returns a SdtListItem object given its zero-based index in the collection.

Properties

NameDescription
countGets number of items in the collection.
selected_valueSpecifies currently selected value in this list. Null value allowed, meaning that no currently selected entry is associated with this list item collection.

Methods

NameDescription
add(item)Adds an item to this collection.
clear()Clears all items from this collection.
remove_at(index)Removes a list item at the specified index.

Examples

Shows how to work with drop down-list structured document tags.

doc = aw.Document()
tag = aw.markup.StructuredDocumentTag(doc, aw.markup.SdtType.DROP_DOWN_LIST, aw.markup.MarkupLevel.BLOCK)
doc.first_section.body.append_child(tag)
list_items = tag.list_items
list_items.add(aw.markup.SdtListItem(value='Value 1'))
assert list_items[0].display_text == list_items[0].value
list_items.add(aw.markup.SdtListItem(display_text='Item 2', value='Value 2'))
list_items.add(aw.markup.SdtListItem(display_text='Item 3', value='Value 3'))
list_items.add(aw.markup.SdtListItem(display_text='Item 4', value='Value 4'))
assert list_items.count == 4
list_items.selected_value = list_items[3]
assert list_items.selected_value.value == 'Value 4'
for item in list_items:
    if item is not None:
        print(f'List item: {item.display_text}, value: {item.value}')
list_items.remove_at(3)
assert list_items.count == 3
list_items.selected_value = list_items[1]
doc.save(ARTIFACTS_DIR + 'StructuredDocumentTag.ListItemCollection.docx')
list_items.clear()
assert list_items.count == 0

See Also