Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Dec 20, 2021 12:08 am

Hi

I'm setting the selected index of a PdfComboBoxField, but when generating the pdf it appears that the selected index value is ignored. Is there an issue with this?

cheers
Steve

Code: Select all
                            Spire.Pdf.Fields.PdfComboBoxField cb = new Spire.Pdf.Fields.PdfComboBoxField(page, uniqueFieldName);
                            cb.Bounds = new RectangleF(searchItem.Position.X, searchItem.Position.Y + offset, size.Width, size.Height);
                            cb.Font = new Spire.Pdf.Graphics.PdfFont(Spire.Pdf.Graphics.PdfFontFamily.Helvetica, 9f);

                            cb.Items.Add(new Spire.Pdf.Fields.PdfListFieldItem("A", "A"));
                            cb.Items.Add(new Spire.Pdf.Fields.PdfListFieldItem("B", "B"));
                            cb.Items.Add(new Spire.Pdf.Fields.PdfListFieldItem("C", "C"));
                            cb.SelectedIndex = 1;

                            document.Form.Fields.Add(cb);

MLLpdfUser
 
Posts: 3
Joined: Thu Dec 16, 2021 11:53 pm

Mon Dec 20, 2021 2:32 am

Hello,

Thanks for your inquiry!

Kindly note that the selected index of the PdfComboBoxField is started from 0. In your code, you set the "cb.SelectedIndex = 1;", so the generated PDF showed the second item.

Please set "cb.SelectedIndex = 0;" if you want the generated PDF to show the first item "A".

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Tue Jan 04, 2022 6:04 am

Hello,

Hope you are doing well!

Has the issue been solved now? Could you please give us some feedback at your convenience?

Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.PDF