GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / GetFormFieldItemValue Method
A unique form field identifier specifying a required form field object. You can obtain this identifier using these methods: AddComboFormField(Single,Single,Single,Single,String,String,Single,Byte,Byte,Byte,Boolean), AddListFormField(Single,Single,Single,Single,String,String,Single,Byte,Byte,Byte,Boolean,Boolean), GetFormFieldId or GetFormFieldChildID.
The index of the required item. It must be a value from 0 to GetFormFieldItemCount-1.
Example





In This Topic
GetFormFieldItemValue Method (GdPicturePDF)
In This Topic
Returns the (export) value of a specific item of a choice form field, that is specified by its unique form field's identifier and it is related to the currently loaded PDF document. The item is identified by its index, that simply represents its position in the item's list.

The item's value is an export value assigned to the specified option, it can be different than the item's text.

Syntax
'Declaration
 
Public Function GetFormFieldItemValue( _
   ByVal FieldId As Integer, _
   ByVal ItemIdx As Integer _
) As String
public string GetFormFieldItemValue( 
   int FieldId,
   int ItemIdx
)
public function GetFormFieldItemValue( 
    FieldId: Integer;
    ItemIdx: Integer
): String; 
public function GetFormFieldItemValue( 
   FieldId : int,
   ItemIdx : int
) : String;
public: string* GetFormFieldItemValue( 
   int FieldId,
   int ItemIdx
) 
public:
String^ GetFormFieldItemValue( 
   int FieldId,
   int ItemIdx
) 

Parameters

FieldId
A unique form field identifier specifying a required form field object. You can obtain this identifier using these methods: AddComboFormField(Single,Single,Single,Single,String,String,Single,Byte,Byte,Byte,Boolean), AddListFormField(Single,Single,Single,Single,String,String,Single,Byte,Byte,Byte,Boolean,Boolean), GetFormFieldId or GetFormFieldChildID.
ItemIdx
The index of the required item. It must be a value from 0 to GetFormFieldItemCount-1.

Return Value

A string representing the value of the selected item. The GetStat method can be subsequently used to determine if this method has been successful.
Remarks
This method is only allowed for use with non-encrypted documents.

It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any.

Just to remind you, that this method is only meaningful for choice form fields, that means for combo boxes or list boxes, otherwise it will fail.

Example
How to retrieve all items and their values in all list boxes in the current document.
Dim caption As String = "Example: GetFormFieldItemValue"
Dim message As String = ""
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
If gdpicturePDF.LoadFromFile("forms.pdf", False) <> GdPictureStatus.OK Then
    message = "The file can't be loaded. Status: " + gdpicturePDF.GetStat().ToString()
    GoTo [error]
End If
Dim count As Integer = gdpicturePDF.GetFormFieldsCount()
If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
    message = "The GetFormFieldsCount() method has failed with the status: " + gdpicturePDF.GetStat().ToString()
    GoTo [error]
End If
If count = 0 Then
    message = "This document includes no form fields."
    GoTo [error]
End If
Dim formID As Integer = 0
Dim type As PdfFormFieldType = PdfFormFieldType.PdfFormFieldTypeUnknown
For i As Integer = 0 To count - 1
    formID = gdpicturePDF.GetFormFieldId(i)
    If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
        message = "The GetFormFieldId() method has failed with the status: " + gdpicturePDF.GetStat().ToString()
        GoTo [error]
    End If
    type = gdpicturePDF.GetFormFieldType(formID)
    If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
        message = "The GetFormFieldType() method has failed with the status: " + gdpicturePDF.GetStat().ToString()
        GoTo [error]
    End If
    If type = PdfFormFieldType.PdfFormFieldTypeList Then
        Dim title As String = gdpicturePDF.GetFormFieldTitle(formID)
        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
            message = message + "listbox: " + title
            Dim itemsCount As Integer = gdpicturePDF.GetFormFieldItemCount(formID)
            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                message = message + "    items: " + itemsCount + vbCrLf
                Dim text As String = "", value As String = ""
                For j As Integer = 0 To itemsCount - 1
                    text = gdpicturePDF.GetFormFieldItemText(formID, j)
                    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                        message = message + "text: " + text
                    Else
                        message = message + "text: " + gdpicturePDF.GetStat().ToString()
                    End If
                    value = gdpicturePDF.GetFormFieldItemValue(formID, j)
                    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                        message = message + "    value: " + value
                    Else
                        message = message + "    value: " + gdpicturePDF.GetStat().ToString()
                    End If
                    message += vbCrLf
                Next
            Else
                message = message + vbCrLf + "The GetFormFieldItemCount() method has failed with the status: " + gdpicturePDF.GetStat().ToString()
                GoTo [error]
            End If
        Else
            message = "The GetFormFieldTitle() method has failed with the status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
    End If
Next
[error]:
If message.Equals("") Then message = "This document includes no list boxes."
MessageBox.Show(message, caption)
gdpicturePDF.Dispose()
string caption = "Example: GetFormFieldItemValue";
string message = "";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("forms.pdf", false) != GdPictureStatus.OK)
{
    message = "The file can't be loaded. Status: " + gdpicturePDF.GetStat().ToString();
    goto error;
}
            
int count = gdpicturePDF.GetFormFieldsCount();
if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
{
    message = "The GetFormFieldsCount() method has failed with the status: " + gdpicturePDF.GetStat().ToString();
    goto error;
}
if (count == 0)
{
    message = "This document includes no form fields.";
    goto error;
}
int formID = 0;
PdfFormFieldType type = PdfFormFieldType.PdfFormFieldTypeUnknown;
for (int i = 0; i < count; i++)
{
    formID = gdpicturePDF.GetFormFieldId(i);
    if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
    {
        message = "The GetFormFieldId() method has failed with the status: " + gdpicturePDF.GetStat().ToString();
        goto error;
    }
    type = gdpicturePDF.GetFormFieldType(formID);
    if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
    {
        message = "The GetFormFieldType() method has failed with the status: " + gdpicturePDF.GetStat().ToString();
        goto error;
    }
    if (type == PdfFormFieldType.PdfFormFieldTypeList)
    {
        string title = gdpicturePDF.GetFormFieldTitle(formID);
        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
        {
            message = message + "listbox: " + title;
            int itemsCount = gdpicturePDF.GetFormFieldItemCount(formID);
            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
            {
                message = message + "    items: " + itemsCount + "\n";
                string text = "", value = "";
                for (int j = 0; j < itemsCount; j++)
                {
                    text = gdpicturePDF.GetFormFieldItemText(formID, j);
                    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                        message = message + "text: " + text;
                    else
                        message = message + "text: " + gdpicturePDF.GetStat().ToString();
                    value = gdpicturePDF.GetFormFieldItemValue(formID, j);
                    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                        message = message + "    value: " + value;
                    else
                        message = message + "    value: " + gdpicturePDF.GetStat().ToString();
                    message += "\n";
                }
            }
            else
            {
                message = message + "\nThe GetFormFieldItemCount() method has failed with the status: " + gdpicturePDF.GetStat().ToString();
                goto error;
            }
        }
        else
        {
            message = "The GetFormFieldTitle() method has failed with the status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
    }
}
error:
if (message.Equals(""))
    message = "This document includes no list boxes.";
MessageBox.Show(message, caption);
gdpicturePDF.Dispose();
See Also