Page 1 of 1
Programmatically select FFT_ComboBox option
Posted: Mon Jul 27, 2020 7:05 am
by shaunh
Hi,
I need to programmatically fill PDF forms with data retrieved from a database using the CORE API SDK. So far I can successfully fill all field types that I have needed to except the FFT_ComboBox field type.
Example code for FFT_RadioButton type is as follows and works fine:
Code: Select all
// Cycle through widgets
for (uint i = 0; i < currentField.WidgetsCount; i++)
{
// Retrieve widget
IPXC_Annotation widget = currentField.Widget[i];
// Comapare with data value
if (widget.OnValue == item.Data)
{
// Set as active
currentField.CheckWidget(i, true);
break;
}
}
I need to do the same for FFT_ComboBox. Although I get the index for the option I cannot select the option.
Code: Select all
string comboValue = string.Empty;
string comboLabel = string.Empty;
bool comboSelected = false;
// Loop through options
for (uint i = 0; i < currentField.OptCount; i++)
{
// Retrieve option
currentField.GetOpt(i, out comboValue, out comboLabel, out comboSelected);
// Comapare with data value
if (comboValue == item.Data)
{
// Set as selected
//currentField.SelectItem(i, true, true); //Does not work
break;
}
}
Can you please advise on code to select the combo option using the retrieved index. Assistance will be greatly appreciated.
Re: Programmatically select FFT_ComboBox option
Posted: Tue Jul 28, 2020 6:54 am
by Sasha - Tracker Dev Team
Hello shaunh,
Here's a sample the CoreAPIDemo holds:
Code: Select all
IPXC_FormField comboBox = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "ComboBox", ref index), PXC_FormFieldType.FFT_ComboBox, 0, ref rcPB);
comboBox.InsertOptRecord("lable1", "First Item");
comboBox.InsertOptRecord("lable2", "Second Item");
comboBox.InsertOptRecord("lable3", "Third Item");
comboBox.InsertOptRecord("lable4", "Forth Item");
comboBox.SelectItem(1, true);
Cheers,
Alex
Re: Programmatically select FFT_ComboBox option
Posted: Tue Jul 28, 2020 8:37 am
by shaunh
Thanks for the response Alex. This confirmed that my code was correct. Found the reason it was not working is because I had to first set the default selected option to false before I could set the new selected item. Something like this...
Code: Select all
string comboValue = string.Empty;
string comboLabel = string.Empty;
bool comboSelected = false;
// Loop through options
for (uint i = 0; i < currentField.OptCount; i++)
{
// Retrieve option
currentField.GetOpt(i, out comboValue, out comboLabel, out comboSelected);
// Clear default selection otherwise you cannot set new selection
if (comboSelected == true)
{
// Set as selected
currentField.SelectItem(i, false);
}
// Comapare with data value
if (comboValue == item.Data)
{
// Set as selected
currentField.SelectItem(i, true);
break;
}
}
Programmatically select FFT_ComboBox option
Posted: Tue Jul 28, 2020 1:08 pm
by Sasha - Tracker Dev Team
Re: Programmatically select FFT_ComboBox option
Posted: Wed Jul 29, 2020 2:32 pm
by shaunh
Hi Alex,
Stuck on the FFT_ListBox type now. Implemented similar code to select items in a multiselect list box. The items are being checked and if debug the code currentField.SelectedItemsCount returns the correct number of items selected. When I save the document all the other field types are filled in correctly but there are no items selected in the multiselect list box. Can you please confirm that my code for the list type is correct, or whether I missed something?
Code: Select all
case PXC_FormFieldType.FFT_ListBox:
//Loop through options and set selected
for (uint i = 0; i < currentField.OptCount; i++)
{
string listValue = string.Empty;
string listLabel = string.Empty;
bool listSelected = false;
// Retrieve option
currentField.GetOpt(i, out listValue, out listLabel, out listSelected);
// If it is the item we are looking for then set item selected
if (listValue == item.Data)
{
currentField.SelectItem(i, true);
}
}
Debug.WriteLine("Items selected: " + currentField.SelectedItemsCount); // can see the items selected increasing here
Re: Programmatically select FFT_ComboBox option
Posted: Wed Jul 29, 2020 2:37 pm
by Sasha - Tracker Dev Team
Hello shaunh,
Please check the CoreAPIDemo application - I'm sure there is a sample on FFT_ListBox.
Cheers,
Alex
Re: Programmatically select FFT_ComboBox option
Posted: Thu Jul 30, 2020 8:13 am
by shaunh
Hi Alex,
I have worked through the CORE API demo code. If I do similar code with programmatically creating a listbox and adding options, then setting the selected option works fine. It does not seem to want to work with a form that already has options. Here is the weird part though, if I programmatically add another option then I CAN set the selected options. Could this be a bug in the SDK?
Code: Select all
// This does not work, no items selected in the list box
currentField.SelectItem(0, true);
currentField.SelectItem(1, true);
currentField.SelectItem(2, true);
// This works, all 3 items selected in the list box
currentField.InsertOptRecord("item9", "item9");
currentField.SelectItem(0, true);
currentField.SelectItem(1, true);
currentField.SelectItem(2, true);
Re: Programmatically select FFT_ComboBox option
Posted: Fri Sep 04, 2020 8:44 am
by shaunh
Hi Alex,
Just following up on this. I had to work around this bug by removing all the entries in the list and then repopulating the list box, which then allows me to set the selected items. Ideally you shouldn't have alter the items in the list box to be able to set the selected items, so definitely something that should be looked at.
Re: Programmatically select FFT_ComboBox option
Posted: Mon Oct 19, 2020 9:16 am
by Sasha - Tracker Dev Team
Hello shaunh,
Sorry for the long reply - we'll be having the major V9 release in the couple of weeks - thus making final preparations and feature updates. Please bump this thread after the release is out - we'll definitely try to fix this issue.
Cheers,
Alex