Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Tue Aug 15, 2023 3:05 pm

Spire.Office for .NET V. 8.2
Developer Subscription

I have a form field of type "CheckBoxFormField" with the name "Kontrollkaestchen27" and would like to show the checkbox as selected.
II determine the control over its Name.

CodeBehind (C#):

using Spire.Xls;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;


Document _doks = new Document();
Section section = _doks.Sections[0];
CheckBoxFormField formField = section.Body.FormFields.ContainsName["Kontrollkaestchen27"];
formField.Checked = true;

I receive the error message:

Cannot apply indexing with [] to an expression of type 'method group'

What's going wrong?

ProPotsdam
 
Posts: 9
Joined: Sun Nov 29, 2020 4:30 pm

Wed Aug 16, 2023 2:39 am

Hello,

Thank you for your inquiry.
Based on the error information you provided, you referenced a method group instead of a specific object. I have made modifications to the code you provided and tested it using the Spire.Office Platinum (Hot Fix)Version: 8.8.0 without any issues. Here is the modified code:
Code: Select all
           Document _doks = new Document();
            Section section = _doks.Sections[0];
            CheckBoxFormField formField = section.Body.FormFields["Kontrollkaestchen27"] as CheckBoxFormField;
            formField.Checked = true;

If you have any other questions or concerns, please feel free to contact us anytime.

Sincerely,
Wenly
E-iceblue support team
User avatar

Wenly.Zhang
 
Posts: 149
Joined: Tue May 16, 2023 2:19 am

Wed Aug 16, 2023 8:21 am

Hi,

:D this worked for me!

Thanks.

ProPotsdam
 
Posts: 9
Joined: Sun Nov 29, 2020 4:30 pm

Wed Aug 16, 2023 9:57 am

Hello,

You're welcome.
If you have other questions about using our products in the future, please feel free to contact us.
Wish you a nice day.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc