DropDownItemCollection Class

A collection of strings that represent all the items in a drop-down form field.

Inheritance Hierarchy


Namespace:  Aspose.Words.Fields
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.8.0


public class DropDownItemCollection : IEnumerable<string>, 

The DropDownItemCollection type exposes the following members.


Public propertyCode exampleCount
Gets the number of elements contained in the collection.
Public propertyCode exampleItem
Gets or sets the element at the specified index.


Public methodCode exampleAdd
Adds a string to the end of the collection.
Public methodCode exampleClear
Removes all elements from the collection.
Public methodCode exampleContains
Determines whether the collection contains the specified value.
Public methodEquals (Inherited from Object.)
Public methodCode exampleGetEnumerator
Returns an enumerator object that can be used to iterate over all items in the collection.
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodCode exampleIndexOf
Returns the zero-based index of the specified value in the collection.
Public methodCode exampleInsert
Inserts a string into the collection at the specified index.
Public methodCode exampleRemove
Removes the specified value from the collection.
Public methodCode exampleRemoveAt
Removes a value at the specified index.
Public methodToString (Inherited from Object.)


Shows how to insert a combo box field and manipulate the elements in its item collection.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Use a document builder to create and populate a combo box
string[] items = { "One", "Two", "Three" };
FormField comboBoxField = builder.InsertComboBox("DropDown", items, 0);

// Get the list of drop down items
DropDownItemCollection dropDownItems = comboBoxField.DropDownItems;

Assert.AreEqual(3, dropDownItems.Count);
Assert.AreEqual("One", dropDownItems[0]);
Assert.AreEqual(1, dropDownItems.IndexOf("Two"));

// We can add an item to the end of the collection or insert it at a desired index
dropDownItems.Insert(3, "Three and a half");
Assert.AreEqual(5, dropDownItems.Count);

// Iterate over the collection and print every element
using (IEnumerator<string> dropDownCollectionEnumerator = dropDownItems.GetEnumerator())
    while (dropDownCollectionEnumerator.MoveNext())

// We can remove elements in the same way we added them
Assert.IsFalse(dropDownItems.Contains("Three and a half"));

doc.Save(ArtifactsDir + "Field.DropDownItemCollection.docx");

// Empty the collection

See Also