FormFieldCollection
This class holds a collection of FormField instances, assigned to the AcroForm of the document. The collection exposes useful properties and methods allowing you to access, add or remove the form fields in a document.
Properties
The FormFieldCollection class exposes an indexer and a Count property allowing you to respectively get a FormField instance by its name or get the number of all form fields in the document.
Methods
There are methods allowing you to easily construct a form field and add it to the collection. Any of those methods accepts a string parameter representing the unique name of the form field. The generated field is then returned from the method so you can customize it if needed. Here is a list of all the methods:
AddPushButton(): Creates a PushButton field and adds it to the collection. The created field is returned as a result from the method.
AddCheckBox(): Creates a CheckBox field and adds it to the collection. The created field is returned as a result from the method.
AddRadioButton(): Creates a RadioButton field and adds it to the collection. The created field is returned as a result from the method.
AddCombTextBox(): Creates a CombTextBox field and adds it to the collection. The created field is returned as a result from the method.
AddTextBox(): Creates a TextBox field and adds it to the collection. The created field is returned as a result from the method.
AddComboBox(): Creates a ComboBox field and adds it to the collection. The created field is returned as a result from the method.
AddListBox(): Creates a ListBox field and adds it to the collection. The created field is returned as a result from the method.
AddSignature(): Creates a Signature field and adds it to the collection. The created field is returned as a result from the method.
Example 1 shows how you can use the listed above methods to generate a form field and add it to the collection.
Example 1: Creating a form field
CombTextBoxField comb = document.AcroForm.FormFields.AddCombTextBox("comb");
comb.MaxLengthOfInputCharacters = 10;
comb.Value = "0123456789";
You can also use several more methods of the class to modify the collection of form fields in the document's AcroForm.
Add(): Accepts parameter of type FormField and inserts it to the collection.
Remove(): Accepts parameter of type FormField and removes it from the collection.
Contains(): Accepts a string representing the form field name. Returns true when a field with such a name is present in the collection, otherwise false.
Example 2: Using the methods of FormFieldCollection
if (document.AcroForm.FormFields.Contains(fieldName))
{
document.AcroForm.FormFields.Remove(document.AcroForm.FormFields[fieldName]);
}