com.aspose.words
Class DropDownItemCollection

java.lang.Object
    extended by com.aspose.words.DropDownItemCollection
All Implemented Interfaces:
java.lang.Iterable

public class DropDownItemCollection 
extends java.lang.Object

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

Example:

Shows how to insert a combo box field, and edit the elements in its item collection.
Document doc = new Document();
DocumentBuilder builder = new 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.
String[] items = {"One", "Two", "Three"};
FormField comboBoxField = builder.insertComboBox("DropDown", items, 0);
DropDownItemCollection dropDownItems = comboBoxField.getDropDownItems();

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertEquals("One", dropDownItems.get(0));
Assert.assertEquals(1, dropDownItems.indexOf("Two"));
Assert.assertTrue(dropDownItems.contains("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("Four");

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

Assert.assertEquals(5, dropDownItems.getCount());

// Iterate over the collection and print every element.
Iterator<String> dropDownCollectionEnumerator = dropDownItems.iterator();

while (dropDownCollectionEnumerator.hasNext())
    System.out.println(dropDownCollectionEnumerator.next());

// 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("Four");

// 2 -  Remove an item at an index:
dropDownItems.removeAt(3);

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertFalse(dropDownItems.contains("Three and a half"));
Assert.assertFalse(dropDownItems.contains("Four"));

doc.save(getArtifactsDir() + "FormFields.DropDownItemCollection.html");

// Empty the whole collection of drop-down items.
dropDownItems.clear();
See Also:
FormField, FormField.DropDownItems

Property Getters/Setters Summary
intgetCount()
           Gets the number of elements contained in the collection.
java.lang.Stringget(int index)
voidset(int index, java.lang.String value)
           Gets or sets the element at the specified index.
 
Method Summary
booleanadd(java.lang.String s)
           Adds a string to the end of the collection.
voidclear()
           Removes all elements from the collection.
booleancontains(java.lang.String value)
           Determines whether the collection contains the specified value.
intindexOf(java.lang.String value)
           Returns the zero-based index of the specified value in the collection.
voidinsert(int index, java.lang.String value)
           Inserts a string into the collection at the specified index.
java.util.Iterator<java.lang.String>iterator()
           Returns an iterator object that can be used to iterate over all items in the collection.
voidremove(java.lang.String name)
           Removes the specified value from the collection.
voidremoveAt(int index)
           Removes a value at the specified index.
 

Property Getters/Setters Detail

getCount

public int getCount()
Gets the number of elements contained in the collection.

Example:

Shows how to insert a combo box field, and edit the elements in its item collection.
Document doc = new Document();
DocumentBuilder builder = new 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.
String[] items = {"One", "Two", "Three"};
FormField comboBoxField = builder.insertComboBox("DropDown", items, 0);
DropDownItemCollection dropDownItems = comboBoxField.getDropDownItems();

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertEquals("One", dropDownItems.get(0));
Assert.assertEquals(1, dropDownItems.indexOf("Two"));
Assert.assertTrue(dropDownItems.contains("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("Four");

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

Assert.assertEquals(5, dropDownItems.getCount());

// Iterate over the collection and print every element.
Iterator<String> dropDownCollectionEnumerator = dropDownItems.iterator();

while (dropDownCollectionEnumerator.hasNext())
    System.out.println(dropDownCollectionEnumerator.next());

// 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("Four");

// 2 -  Remove an item at an index:
dropDownItems.removeAt(3);

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertFalse(dropDownItems.contains("Three and a half"));
Assert.assertFalse(dropDownItems.contains("Four"));

doc.save(getArtifactsDir() + "FormFields.DropDownItemCollection.html");

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

get/set

public java.lang.String get(int index) / public void set(int index, java.lang.String value)
Gets or sets the element at the specified index.

Example:

Shows how to insert a combo box field, and edit the elements in its item collection.
Document doc = new Document();
DocumentBuilder builder = new 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.
String[] items = {"One", "Two", "Three"};
FormField comboBoxField = builder.insertComboBox("DropDown", items, 0);
DropDownItemCollection dropDownItems = comboBoxField.getDropDownItems();

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertEquals("One", dropDownItems.get(0));
Assert.assertEquals(1, dropDownItems.indexOf("Two"));
Assert.assertTrue(dropDownItems.contains("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("Four");

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

Assert.assertEquals(5, dropDownItems.getCount());

// Iterate over the collection and print every element.
Iterator<String> dropDownCollectionEnumerator = dropDownItems.iterator();

while (dropDownCollectionEnumerator.hasNext())
    System.out.println(dropDownCollectionEnumerator.next());

// 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("Four");

// 2 -  Remove an item at an index:
dropDownItems.removeAt(3);

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertFalse(dropDownItems.contains("Three and a half"));
Assert.assertFalse(dropDownItems.contains("Four"));

doc.save(getArtifactsDir() + "FormFields.DropDownItemCollection.html");

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

Method Detail

add

public boolean add(java.lang.String s)
Adds a string to the end of the collection.
Parameters:
value - The string to add to the end of the collection.
Returns:
true (as per the general contract of Collection.add).

Example:

Shows how to insert a combo box field, and edit the elements in its item collection.
Document doc = new Document();
DocumentBuilder builder = new 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.
String[] items = {"One", "Two", "Three"};
FormField comboBoxField = builder.insertComboBox("DropDown", items, 0);
DropDownItemCollection dropDownItems = comboBoxField.getDropDownItems();

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertEquals("One", dropDownItems.get(0));
Assert.assertEquals(1, dropDownItems.indexOf("Two"));
Assert.assertTrue(dropDownItems.contains("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("Four");

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

Assert.assertEquals(5, dropDownItems.getCount());

// Iterate over the collection and print every element.
Iterator<String> dropDownCollectionEnumerator = dropDownItems.iterator();

while (dropDownCollectionEnumerator.hasNext())
    System.out.println(dropDownCollectionEnumerator.next());

// 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("Four");

// 2 -  Remove an item at an index:
dropDownItems.removeAt(3);

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertFalse(dropDownItems.contains("Three and a half"));
Assert.assertFalse(dropDownItems.contains("Four"));

doc.save(getArtifactsDir() + "FormFields.DropDownItemCollection.html");

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

clear

public void clear()
Removes all elements from the collection.

Example:

Shows how to insert a combo box field, and edit the elements in its item collection.
Document doc = new Document();
DocumentBuilder builder = new 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.
String[] items = {"One", "Two", "Three"};
FormField comboBoxField = builder.insertComboBox("DropDown", items, 0);
DropDownItemCollection dropDownItems = comboBoxField.getDropDownItems();

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertEquals("One", dropDownItems.get(0));
Assert.assertEquals(1, dropDownItems.indexOf("Two"));
Assert.assertTrue(dropDownItems.contains("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("Four");

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

Assert.assertEquals(5, dropDownItems.getCount());

// Iterate over the collection and print every element.
Iterator<String> dropDownCollectionEnumerator = dropDownItems.iterator();

while (dropDownCollectionEnumerator.hasNext())
    System.out.println(dropDownCollectionEnumerator.next());

// 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("Four");

// 2 -  Remove an item at an index:
dropDownItems.removeAt(3);

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertFalse(dropDownItems.contains("Three and a half"));
Assert.assertFalse(dropDownItems.contains("Four"));

doc.save(getArtifactsDir() + "FormFields.DropDownItemCollection.html");

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

contains

public boolean contains(java.lang.String value)
Determines whether the collection contains the specified value.
Parameters:
value - Case-sensitive value to locate.
Returns:
True if the item is found in the collection; otherwise, false.

Example:

Shows how to insert a combo box field, and edit the elements in its item collection.
Document doc = new Document();
DocumentBuilder builder = new 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.
String[] items = {"One", "Two", "Three"};
FormField comboBoxField = builder.insertComboBox("DropDown", items, 0);
DropDownItemCollection dropDownItems = comboBoxField.getDropDownItems();

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertEquals("One", dropDownItems.get(0));
Assert.assertEquals(1, dropDownItems.indexOf("Two"));
Assert.assertTrue(dropDownItems.contains("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("Four");

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

Assert.assertEquals(5, dropDownItems.getCount());

// Iterate over the collection and print every element.
Iterator<String> dropDownCollectionEnumerator = dropDownItems.iterator();

while (dropDownCollectionEnumerator.hasNext())
    System.out.println(dropDownCollectionEnumerator.next());

// 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("Four");

// 2 -  Remove an item at an index:
dropDownItems.removeAt(3);

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertFalse(dropDownItems.contains("Three and a half"));
Assert.assertFalse(dropDownItems.contains("Four"));

doc.save(getArtifactsDir() + "FormFields.DropDownItemCollection.html");

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

indexOf

public int indexOf(java.lang.String value)
Returns the zero-based index of the specified value in the collection.
Parameters:
value - The case-sensitive value to locate.
Returns:
The zero based index. Negative value if not found.

Example:

Shows how to insert a combo box field, and edit the elements in its item collection.
Document doc = new Document();
DocumentBuilder builder = new 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.
String[] items = {"One", "Two", "Three"};
FormField comboBoxField = builder.insertComboBox("DropDown", items, 0);
DropDownItemCollection dropDownItems = comboBoxField.getDropDownItems();

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertEquals("One", dropDownItems.get(0));
Assert.assertEquals(1, dropDownItems.indexOf("Two"));
Assert.assertTrue(dropDownItems.contains("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("Four");

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

Assert.assertEquals(5, dropDownItems.getCount());

// Iterate over the collection and print every element.
Iterator<String> dropDownCollectionEnumerator = dropDownItems.iterator();

while (dropDownCollectionEnumerator.hasNext())
    System.out.println(dropDownCollectionEnumerator.next());

// 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("Four");

// 2 -  Remove an item at an index:
dropDownItems.removeAt(3);

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertFalse(dropDownItems.contains("Three and a half"));
Assert.assertFalse(dropDownItems.contains("Four"));

doc.save(getArtifactsDir() + "FormFields.DropDownItemCollection.html");

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

insert

public void insert(int index, java.lang.String value)
Inserts a string into the collection at the specified index.
Parameters:
index - The zero-based index at which value is inserted.
value - The string to insert.

Example:

Shows how to insert a combo box field, and edit the elements in its item collection.
Document doc = new Document();
DocumentBuilder builder = new 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.
String[] items = {"One", "Two", "Three"};
FormField comboBoxField = builder.insertComboBox("DropDown", items, 0);
DropDownItemCollection dropDownItems = comboBoxField.getDropDownItems();

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertEquals("One", dropDownItems.get(0));
Assert.assertEquals(1, dropDownItems.indexOf("Two"));
Assert.assertTrue(dropDownItems.contains("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("Four");

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

Assert.assertEquals(5, dropDownItems.getCount());

// Iterate over the collection and print every element.
Iterator<String> dropDownCollectionEnumerator = dropDownItems.iterator();

while (dropDownCollectionEnumerator.hasNext())
    System.out.println(dropDownCollectionEnumerator.next());

// 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("Four");

// 2 -  Remove an item at an index:
dropDownItems.removeAt(3);

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertFalse(dropDownItems.contains("Three and a half"));
Assert.assertFalse(dropDownItems.contains("Four"));

doc.save(getArtifactsDir() + "FormFields.DropDownItemCollection.html");

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

iterator

public java.util.Iterator<java.lang.String> iterator()
Returns an iterator object that can be used to iterate over all items in the collection.

Example:

Shows how to insert a combo box field, and edit the elements in its item collection.
Document doc = new Document();
DocumentBuilder builder = new 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.
String[] items = {"One", "Two", "Three"};
FormField comboBoxField = builder.insertComboBox("DropDown", items, 0);
DropDownItemCollection dropDownItems = comboBoxField.getDropDownItems();

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertEquals("One", dropDownItems.get(0));
Assert.assertEquals(1, dropDownItems.indexOf("Two"));
Assert.assertTrue(dropDownItems.contains("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("Four");

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

Assert.assertEquals(5, dropDownItems.getCount());

// Iterate over the collection and print every element.
Iterator<String> dropDownCollectionEnumerator = dropDownItems.iterator();

while (dropDownCollectionEnumerator.hasNext())
    System.out.println(dropDownCollectionEnumerator.next());

// 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("Four");

// 2 -  Remove an item at an index:
dropDownItems.removeAt(3);

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertFalse(dropDownItems.contains("Three and a half"));
Assert.assertFalse(dropDownItems.contains("Four"));

doc.save(getArtifactsDir() + "FormFields.DropDownItemCollection.html");

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

remove

public void remove(java.lang.String name)
Removes the specified value from the collection.
Parameters:
name - The case-sensitive value to remove.

Example:

Shows how to insert a combo box field, and edit the elements in its item collection.
Document doc = new Document();
DocumentBuilder builder = new 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.
String[] items = {"One", "Two", "Three"};
FormField comboBoxField = builder.insertComboBox("DropDown", items, 0);
DropDownItemCollection dropDownItems = comboBoxField.getDropDownItems();

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertEquals("One", dropDownItems.get(0));
Assert.assertEquals(1, dropDownItems.indexOf("Two"));
Assert.assertTrue(dropDownItems.contains("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("Four");

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

Assert.assertEquals(5, dropDownItems.getCount());

// Iterate over the collection and print every element.
Iterator<String> dropDownCollectionEnumerator = dropDownItems.iterator();

while (dropDownCollectionEnumerator.hasNext())
    System.out.println(dropDownCollectionEnumerator.next());

// 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("Four");

// 2 -  Remove an item at an index:
dropDownItems.removeAt(3);

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertFalse(dropDownItems.contains("Three and a half"));
Assert.assertFalse(dropDownItems.contains("Four"));

doc.save(getArtifactsDir() + "FormFields.DropDownItemCollection.html");

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

removeAt

public void removeAt(int index)
Removes a value at the specified index.
Parameters:
index - The zero based index.

Example:

Shows how to insert a combo box field, and edit the elements in its item collection.
Document doc = new Document();
DocumentBuilder builder = new 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.
String[] items = {"One", "Two", "Three"};
FormField comboBoxField = builder.insertComboBox("DropDown", items, 0);
DropDownItemCollection dropDownItems = comboBoxField.getDropDownItems();

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertEquals("One", dropDownItems.get(0));
Assert.assertEquals(1, dropDownItems.indexOf("Two"));
Assert.assertTrue(dropDownItems.contains("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("Four");

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

Assert.assertEquals(5, dropDownItems.getCount());

// Iterate over the collection and print every element.
Iterator<String> dropDownCollectionEnumerator = dropDownItems.iterator();

while (dropDownCollectionEnumerator.hasNext())
    System.out.println(dropDownCollectionEnumerator.next());

// 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("Four");

// 2 -  Remove an item at an index:
dropDownItems.removeAt(3);

Assert.assertEquals(3, dropDownItems.getCount());
Assert.assertFalse(dropDownItems.contains("Three and a half"));
Assert.assertFalse(dropDownItems.contains("Four"));

doc.save(getArtifactsDir() + "FormFields.DropDownItemCollection.html");

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

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.