For several hours I have been trying to set the selected index/value on a comboBoxField, so it can show up as default when opening the PDF generated, but to no avail. I can see that while debugging my SelectedIndex, SelectedItem, and SelectedValue are populated with the value I want as default, but when the PDF is generated, the dropdown is blank (but the options are available to be selected). I dont have any problems with PdfTextBoxField, those are being populated just fine. My code for the ComboboxField is the following (I'm trying to hardcode the first option as selected index to test):
- Code: Select all
PdfComboBoxField comboBoxField = new PdfComboBoxField(page, fieldId);
comboBoxField.Bounds = new RectangleF(fieldX + fieldMaxWidth + 2, fieldY, fieldMaxWidth, fieldHeight);
comboBoxField.BorderWidth = 0.75f;
comboBoxField.BackColor = Color.LightSkyBlue;
comboBoxField.Font = new PdfFont(PdfFontFamily.Helvetica, 9f);
comboBoxField.Editable = true;
foreach (XPathNavigator itemNode in itemNodes)
{
String text = itemNode.SelectSingleNode("text()").Value;
comboBoxField.Items.Add(new PdfListFieldItem(text, text));
}
comboBoxField.SelectedIndex = 0;
form.Fields.Add(comboBoxField);
Everything works except for this selected index. Please let me know your thoughts on this code.
Best,
Diego