DropDownItemCollection Class
A collection of strings that represent all the items in a drop-down form field.
Inheritance Hierarchy
SystemObject
  Aspose.Words.FieldsDropDownItemCollection

Namespace: Aspose.Words.Fields
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.11
Syntax
public class DropDownItemCollection : IEnumerable<string>, 
	IEnumerable

The DropDownItemCollection type exposes the following members.

Properties
  NameDescription
Public propertyCode exampleCount
Gets the number of elements contained in the collection.
Public propertyCode exampleItem
Gets or sets the element at the specified index.
Methods
  NameDescription
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.)
Protected methodFinalize (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.
Protected methodMemberwiseClone (Inherited from Object.)
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.)
Remarks
Examples
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"));
Assert.IsTrue(dropDownItems.Contains("Three"));

// We can add an item to the end of the collection or insert it at a desired index
dropDownItems.Add("Four");
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())
    {
        string currentItem = dropDownCollectionEnumerator.Current;
        Console.WriteLine(currentItem);
    }
}

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

doc.Save(ArtifactsDir + "Fields.DropDownItems.docx");
See Also