Programmatically hide the first row of a repeating table in InfoPath

Applies to: InfoPath 2007

Learn how you can use an InfoPath hidden field and conditional formatting to programmatically hide the first row of a repeating table in InfoPath.

ADVERTISEMENTS

Problem

You have a repeating table on an InfoPath form, which you want to add rows to and then click a button to hide the first row of the repeating table.

Solution

Use conditional formatting and an InfoPath hidden field to programmatically hide the first row of a repeating table.

Discussion

You can programmatically hide the first row in an InfoPath repeating table as follows:

  1. Create a new Blank InfoPath form template.
  2. Add a Repeating Table and Button control to the form template.
  3. On the Data Source task pane, right-click the group2 node of the repeating table and select Add from the drop-down menu that appears.
  4. On the Add Field or Group dialog box, type hidden in the Name text box and click OK. The Main data source of the InfoPath form template should now resemble the following figure.

    The Main data source of the InfoPath form template
    Figure 1. The Main data source of the InfoPath form template.

  5. On the InfoPath form template, select the repeating table, and then from the Format menu, choose Conditional Formatting.
  6. On the Conditional Formatting dialog box, click Add.
  7. On the Conditional Format dialog box, set up a condition that says:

    hidden is equal to "1"

  8. On the Conditional Format dialog box, select the Hide this control check box, and click OK.
  9. On the Conditional Formatting dialog box, click OK.
  10. Double-click the button control to open its Properties dialog box.
  11. On the Button Properties dialog box, click Edit Form Code.
  12. Add the following C# code to the Clicked event handler of the button control:

    XPathNavigator root = MainDataSource.CreateNavigator();
    root.SelectSingleNode(
    "//my:hidden[1]", NamespaceManager).SetValue("1");

  13. Save your work and build the code for the InfoPath form template.

Now whenever you fill out the InfoPath form, add a few rows to the repeating table and click on the button, the first row in the repeating table will be hidden.

 


Related InfoPath Articles:

 

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners

InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013

InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners

InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010

InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers

InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services