Collapsible Sections

Collapsible Sections


Mark asks:


How do I create a collapsible section? That is, a section that can show/hide child controls, whether they are required or not. I can't use an optional section, because it requires binding.


The easiest way to do this is to this is using Conditional Formatting. Select the Section control, then pick Format | Conditional Formatting.... Add a rule where the formatting is “Hide this control”.


Adding conditional visibility to a section


We often call this “conditional visibility.” Like everything in InfoPath, the view state is driven entirely by the data, so you need something in your data which maps to the expand/collapse state. One common approach is to add an attribute field to the group element the section is bound to. It shows up in your data when saved, and the expand/collapse state is saved when users save the form.


Designing a collapsible section


Bind a checkbox to the attribute, and you now have UI which lets the user control the state. If you prefer a button, you can create a rule which sets the value of the attribute; use two buttons with more conditional visibility rules to swap the label (e.g. between a + and a – to look like a TreeView). You can also write code which modifies the value of the attribute, and the section will show or hide.


Comments (6)

  1. Thanks! I’ll give it a try and post my experiences…

  2. Works like a dream…thanks!

  3. chandrakanth says:

    it is great work. Preferably we can use an arrow.gif in the horizontal direction and once the section get expanded we can place the GIF pointing down. User will click on the GIF to expand or collapse the sections.

  4. Rayman says:

    In InfoPath 2010 against an existing SharePoint list, it appears I cannot add additional sections where normally in 2007 I would do exactly as you describe. I can pput more than one on the form, but the advanced view only shows one _RW section and I cannot then hide one from a form element in another.

  5. Dan says:

    Can I have a table in a collapsible Section?  I've tried it, and it doesn't like me putting a table inside a section.  I need this for proper formatting.  Thanks.

Skip to main content