Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6915665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:30:13+00:00 2026-05-27T09:30:13+00:00

How does one get a handle to a CheckBox control that’s embedded in a

  • 0

How does one get a handle to a CheckBox control that’s embedded in a Word document using OpenXML?

You would think that either Paragraph.ControlPropertiesPart or Paragraph.Descendents() would achieve something but in every single case I get a null type returned.

I can traverse down the document tree using the actual XML structure, but this seems cumbersome.

Suggestions welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:30:14+00:00Added an answer on May 27, 2026 at 9:30 am

    The code below shows how to enumerate all checkboxes in a word document by
    using the Decendants<CheckBox>() method on the docuement’s body.

    using (WordprocessingDocument doc = WordprocessingDocument.Open("c:\\temp\\checkbox.docx", true))
    {
      foreach (CheckBox cb in doc.MainDocumentPart.Document.Body.Descendants<CheckBox>())
      {
        Console.Out.WriteLine(cb.LocalName);
    
        FormFieldName cbName = cb.Parent.ChildElements.First<FormFieldName>();
        Console.Out.WriteLine(cbName.Val);
    
        DefaultCheckBoxFormFieldState defaultState = cb.GetFirstChild<DefaultCheckBoxFormFieldState>();
        Checked state = cb.GetFirstChild<Checked>();
    
        Console.Out.WriteLine(defaultState.Val.ToString());
    
        if (state.Val == null) // In case checkbox is checked the val attribute is null
        {
          Console.Out.WriteLine("CHECKED");
        }
        else
        {
          Console.Out.WriteLine(state.Val.ToString());
        }
      }
    }
    

    To determine the name of a given checkbox input element you have to access the
    Parent property of the CheckBox instance and then search for the FormFieldName element (to assign a name to a checkbox use the Properties Dialog in Microsoft Word).

    The DefaultCheckBoxFormFieldState Val property holds the default state for the checkbox.
    Furthermore the Val property of the Checked element holds the actual checked state
    of the CheckBox instance. Note, for Microsoft Word 2007 the Val property is null if
    the checkbox is checked.

    BEGIN EDIT

    I’d like to extend my answer. In fact, there are two kinds of checkbox controls on the MS Word developer tab – a legacy checkbox and an ActiveX control checkbox. The code shown above can be used to enumerte legacy checkboxes in a word document (see this article on how to create a legacy checkbox).

    As far as I know, you can’t use the OpenXML SDK to get/set values for an ActiveX checkbox.
    However you can enumerate ActiveX controls using the following code:

    foreach (Control ctrl in doc.MainDocumentPart.Document.Body.Descendants<Control>())
    {
       Console.Out.WriteLine(ctrl.Id);
       Console.Out.WriteLine(ctrl.Name);
       Console.Out.WriteLine(ctrl.ShapeId);
    }
    

    To determine whether or not a given Control is a checkbox you have to ckeck the class ID of the Control. The class ID of a checkbox is {8BD21D40-EC42-11CE-9E0D-00AA006002F3}.
    Here is a code sample to get the class ID (I don’t know if there is an easier way…):

    OpenXmlPart part = doc.MainDocumentPart.GetPartById(ctrl.Id);
    OpenXmlReader re = OpenXmlReader.Create(part.GetStream());
    re.Read();
    OpenXmlElement el = re.LoadCurrentElement();          
    if(el.GetAttribute("classid", el.NamespaceUri).Value == "{8BD21D40-EC42-11CE-9E0D-00AA006002F3}")
    {
      Console.WriteLine("Checkbox found...");
    }
    re.Close();
    

    END EDIT

    EDIT 2

    I didn’t realize that there is a new checkbox control in Word 2010 (Thanks to Dennis
    Palmer).

    To enumerate those new checkbox controls you can use the following code:

    using (WordprocessingDocument doc = WordprocessingDocument.Open(filename, true))
    {
       MainDocumentPart mp = doc.MainDocumentPart;
    
       foreach(SdtContentCheckBox cb in mp.Document.Body.Descendants<SdtContentCheckBox>())
       {         
         if(cb.Checked.Val == "1");
         {
           Console.Out.WriteLine("CHECKED");  
         }           
       }
    }
    

    END EDIT 2

    Hope, this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does any one know if its possible to animate app.current.mainwindow.width so that you get
How does one handle logging in and out/creating users, without using Google Users? I'd
How does one get a list of running applications as shown in the "Applications"
does any one know how to get the current motherboard, processor or HD temperature
How does one go about authoring a Regular Expression that matches against all strings
How does one handle a DateTime with a NOT NULL ? I want to
How does one invoke a groovy method that prints to stdout, appending the output
How does one get a slider working with jQuery. HTML: <head> <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js></script> <script
How does one handle bad formats in routes in Rails 2.3? For instance suppose
In an object-oriented programming style does how does one tend to handle graphics? Should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.