Aspose::Words::Fields::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.

class DropDownItemCollection : public System::Collections::Generic::IEnumerable<System::String>,
                               public Aspose::Words::IComplexAttr

Methods

MethodDescription
Add(const System::String&)Adds a string to the end of the collection.
begin()
begin() const
cbegin() const
cend() const
Clear()Removes all elements from the collection.
Contains(const System::String&)Determines whether the collection contains the specified value.
end()
end() const
get_Count()Gets the number of elements contained in the collection.
GetEnumerator() overrideReturns an enumerator object that can be used to iterate over all items in the collection.
GetType() const override
idx_get(int32_t)Gets or sets the element at the specified index.
idx_set(int32_t, const System::String&)Gets or sets the element at the specified index.
IndexOf(const System::String&)Returns the zero-based index of the specified value in the collection.
Insert(int32_t, const System::String&)Inserts a string into the collection at the specified index.
Is(const System::TypeInfo&) const override
Remove(const System::String&)Removes the specified value from the collection.
RemoveAt(int32_t)Removes a value at the specified index.
static Type()
virtualizeBeginConstIterator() const override
virtualizeBeginIterator() override
virtualizeEndConstIterator() const override
virtualizeEndIterator() override

Typedefs

TypedefDescription
const_iterator
iterator
iterator_holder_type
virtualized_iterator
virtualized_iterator_element

Examples

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

auto doc = MakeObject<Document>();
auto builder = MakeObject<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.
ArrayPtr<String> items = MakeArray<String>({u"One", u"Two", u"Three"});
SharedPtr<FormField> comboBoxField = builder->InsertComboBox(u"DropDown", items, 0);
SharedPtr<DropDownItemCollection> dropDownItems = comboBoxField->get_DropDownItems();

ASSERT_EQ(3, dropDownItems->get_Count());
ASSERT_EQ(u"One", dropDownItems->idx_get(0));
ASSERT_EQ(1, dropDownItems->IndexOf(u"Two"));
ASSERT_TRUE(dropDownItems->Contains(u"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:
dropDownItems->Add(u"Four");

// 2 -  Insert an item before another item at a specified index:
dropDownItems->Insert(3, u"Three and a half");

ASSERT_EQ(5, dropDownItems->get_Count());

// Iterate over the collection and print every element.
{
    SharedPtr<System::Collections::Generic::IEnumerator<String>> dropDownCollectionEnumerator = dropDownItems->GetEnumerator();
    while (dropDownCollectionEnumerator->MoveNext())
    {
        std::cout << dropDownCollectionEnumerator->get_Current() << std::endl;
    }
}

// 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:
dropDownItems->Remove(u"Four");

// 2 -  Remove an item at an index:
dropDownItems->RemoveAt(3);

ASSERT_EQ(3, dropDownItems->get_Count());
ASSERT_FALSE(dropDownItems->Contains(u"Three and a half"));
ASSERT_FALSE(dropDownItems->Contains(u"Four"));

doc->Save(ArtifactsDir + u"FormFields.DropDownItemCollection.html");

// Empty the whole collection of drop-down items.
dropDownItems->Clear();

See Also