Programmatically select FFT_ComboBox option

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
shaunh
User
Posts: 23
Joined: Mon May 18, 2020 7:03 am

Programmatically select FFT_ComboBox option

Post by shaunh » Mon Jul 27, 2020 7:05 am

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.

User avatar
Sasha - Tracker Dev Team
User
Posts: 5037
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Programmatically select FFT_ComboBox option

Post by Sasha - Tracker Dev Team » Tue Jul 28, 2020 6:54 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

shaunh
User
Posts: 23
Joined: Mon May 18, 2020 7:03 am

Re: Programmatically select FFT_ComboBox option

Post by shaunh » Tue Jul 28, 2020 8:37 am

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;
	}
}

User avatar
Sasha - Tracker Dev Team
User
Posts: 5037
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Programmatically select FFT_ComboBox option

Post by Sasha - Tracker Dev Team » Tue Jul 28, 2020 1:08 pm

:)
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

shaunh
User
Posts: 23
Joined: Mon May 18, 2020 7:03 am

Re: Programmatically select FFT_ComboBox option

Post by shaunh » Wed Jul 29, 2020 2:32 pm

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

User avatar
Sasha - Tracker Dev Team
User
Posts: 5037
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Programmatically select FFT_ComboBox option

Post by Sasha - Tracker Dev Team » Wed Jul 29, 2020 2:37 pm

Hello shaunh,

Please check the CoreAPIDemo application - I'm sure there is a sample on FFT_ListBox.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

shaunh
User
Posts: 23
Joined: Mon May 18, 2020 7:03 am

Re: Programmatically select FFT_ComboBox option

Post by shaunh » Thu Jul 30, 2020 8:13 am

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);

shaunh
User
Posts: 23
Joined: Mon May 18, 2020 7:03 am

Re: Programmatically select FFT_ComboBox option

Post by shaunh » Fri Sep 04, 2020 8:44 am

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.

Post Reply