DropDownItemCollectionClear Method
Removes all elements from the collection.

Namespace: Aspose.Words.Fields
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.12
Syntax
public void Clear()
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