I need to add index for each option added to the ComboBox. Is there any property available for adding indexes as well with the option ?
By default each option added in the ComboBox has a value. If you add first options its index will be 1 and if you add another option in the comboBox its index will be 2 and so on. We don’t have any property/method to set the index of the option as it is set by default.
You are mixing Zindex with Index. Zindex is different. It gets or sets a int value that indicates the Z-order of the graph. A graph with larger ZIndex will be placed over the graph with smaller ZIndex. ZIndex can be negative. Graph with negative ZIndex will be placed behind the text in the page.
If you still face any issue, please share your sample code.
dtCollection is a DataTable which has following data:
0 - Unknown
1 - Growth
2 - Core
So if it is not possible to add these indexes along with options, could you please provide any other alternative to this if possible or any other property of ComboBox would be okay too.
Please see following sample code snippet for getting the index of the selected option of the combo box and also it shows how you can get all options of the combo box.
C#
Document pdfDocument = new Document(dataDir + “ComboBox_out.pdf”);
ComboBoxField comboField = pdfDocument.Form[“field_1”] as ComboBoxField;
Console.WriteLine(comboField.Selected); // list all options of the combo box field foreach (Option option in comboField.Options) { Console.WriteLine(option.Name); }
If you still face any issue, please feel free to contact us.
Thanks for sharing this example. I tested this code at my end.
First of all my scenario here is this:
Step1) Generating PDF file with controls and populating data to those controls.
Step2) Reading generated PDF back into system.
Data that i want to bind to ComboBox control is similar to this:
10 - Red
11 - Blue
15 - Green
By now i know that when we bind this data to ComboBox i would have Red at index 1, Blue at 2 and Green at 3…
While i was testing your sample, i noticed that for Name as well as for value property Red, Green and Blue is being returned. Ideally value field should have returned 10,11,15…
Console.WriteLine(option.Name);
Console.WriteLine(option.Value);
Having said this, Could you please tell me which method of ComboBox field i should use in Step1 to generate
ComboBox with this so that i can use values:
10 - Red
11 - Blue
15 - Green
Note: i am using addOption field to create dropdown which has only 2 overloads and both does not allow you to add value and that is the reason i cannot add value
Is there any alternative to this solution other than ComboBox?
I am afraid currently Aspose.Pdf for .NET doesn’t support adding different name and value of a combobox option. When you use AddOption(“Red”) it adds label and value same. However, I have logged an enhancement ticket PDFNET-42348 in our issue tracking system. We will further look into it and will update you within this forum thread as soon as this feature is implemented.
Please check below code snippet to get the index of the options added in the Combo box.
ComboBoxField comboField = pdfDocument.Form[“field_1”] as ComboBoxField; Console.WriteLine(comboField.Selected); // list all options of the combo box field foreach (Option option in comboField.Options) { Console.WriteLine(option.Name);
Console.WriteLine(option.Index); // -1 means an empty option }
If you need further assistance, please feel free to contact us.