The best way to select multiple items in a listbox

Hi everyone,


What I am trying to do is change SelectedItems in an Aspose.Pdf.InteractiveFeatures.Forms.ListBoxField. Lets say we have a ListBoxField listbox whose options are ‘a’ ,‘b’, ‘c’ and ‘d’. And I want to change the SelectedItems of this listbox to be ‘b’ and ‘d’ . Is there a convenient way to do this(or a function that can do this line SetListSelecdtion in iText) ? It would be better if I can see some snippets on this. Thanks.

Hi Arashi,


Thanks for contacting support.

In order to accomplish your requirement, you need to specify the item or index of items to be selected using Selected property of ListBoxField class. Please take a look over following code snippet.

In case you encounter any issue, please share the resource PDF so that we can test the scenario in our environment.

[C#]

var pdfDoc = new Document(@“C:\pdftest\sample.pdf”);<o:p></o:p>

foreach (Field field in pdfDoc.Form)

{

FindAndSetField(field);

}

pdfDoc.Save(@"C:\pdftest\ToAspose\ToAspose\2013_I-9_Filled_NEW.pdf");

pdfDoc.Dispose();

private static void FindAndSetField(Field field)

{

if (field.FullName == "form1[0].#subform[6].State[0]")

{

var chexkboxField = (Aspose.Pdf.InteractiveFeatures.Forms.ListBoxField)field;

foreach (var item in chexkboxField.Options.Cast<Option>())

{

if (item.Value == "CA")

{

try

{

chexkboxField.Selected = item.Index;

}

catch (ArgumentException)

{

}

break;

}

}

}

else if (field.Count > 0)

{

foreach (Field subField in field)

{

FindAndSetField(subField);

}

}

}