Q:
I am very impressed with your SDK-s ability to read and update forms.
I have searched your site to find out how to populate a combo-box but
have not seen any examples for this. How to I set values on a combo-
box or a multi-selection list?
----
A:
Combo boxes and list boxes are represented in PDF using the 'choice'
field type (in PDFNet it is pdftron.PDF.Field.Type.e_choice). A choice
field contains several text items, one or more of which may be
selected as the field value. The items may be presented to the user in
either of two forms:
- A scrollable list box
- A combo box consisting of a drop-down list optionally accompanied by
an editable text box in which the user can type a value other than the
predefined choices (In PDFNet they are differentiated using
pdftron.PDF.Field.Flag.e_combo flag; If this flag is set, the field is
a combo box otherwise the field is a list box).
To set the value of any form field, you can use Field.SetValue(value)
method.
In case of choice fields, the value identifies the item or items
currently selected in the choice field. If the field does not allow
multiple selection (that is if the
pdftron.PDF.Field.Flag.e_multiselect is not set) or if multiple
selection is supported but only one item is currently selected, the
value should be a text string (i.e. one of the values specified in
field dictionary's 'Opt' array). For example:
C#: field.SetValue(pdftron.SDF.Obj.CreateString("Item1"));
VB.Net: field.SetValue(pdftron.SDF.Obj.CreateString("Item1"))
C++: field.SetValue(new pdftron::SDF::Str("Item1"));
If multiple items are selected, the value should be an array of such
strings. For example:
C#:
Obj selection = pdftron.SDF.Obj.CreateArray();
selection.PushBack(pdftron.SDF.Obj.CreateString("Item1"));
selection.PushBack(pdftron.SDF.Obj.CreateString("Item2"));
selection.PushBack(pdftron.SDF.Obj.CreateString("Item4"));
field.SetValue(selection);
C++:
Obj* selection = new pdftron::SDF::Array();
selection.PushBack(new Str("Item1"));
selection.PushBack(new ("Item2"));
selection.PushBack(new ("Item4"));
field.SetValue(selection);
If no items should be selected the value should be set to Null. For
example:
C#: field.SetValue(pdftron.SDF.Obj.CreateNull());
VB.Net: field.SetValue(pdftron.SDF.Obj.CreateNull());
C++: field.SetValue(new pdftron::SDF::Null());
The default value for 'choice' field types is null, indicating that no
item is currently selected.