Programmatically hide the first row of a repeating table in InfoPath
Learn how you can use an InfoPath hidden field and conditional formatting to programmatically hide the first row of a repeating table in InfoPath.
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.
Use conditional formatting and an InfoPath hidden field to programmatically hide the first row of a repeating table.
You can programmatically hide the first row in an InfoPath repeating table as follows:
- Create a new Blank InfoPath form template.
- Add a Repeating Table and Button control to the form template.
- 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.
- 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 1. The Main data source of the InfoPath form template.
- On the InfoPath form template, select the repeating table, and then from the Format menu, choose Conditional Formatting.
- On the Conditional Formatting dialog box, click Add.
On the Conditional Format dialog box, set up a condition that says:
hidden is equal to "1"
- On the Conditional Format dialog box, select the Hide this control check box, and click OK.
- On the Conditional Formatting dialog box, click OK.
- Double-click the button control to open its Properties dialog box.
- On the Button Properties dialog box, click Edit Form Code.
Add the following C# code to the Clicked event handler of the button control:
XPathNavigator root = MainDataSource.CreateNavigator();
- 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.
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 of S.Y.M. Wong-A-Ton. 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, S.Y.M. Wong-A-Ton.
Related InfoPath Articles:
- How to create a hidden field in InfoPath
- Programmatically delete the first row of a repeating table in InfoPath
- Programmatically delete all of the rows of a repeating table in InfoPath
- InfoPath Basics: Repeating control basics in InfoPath
- What is InfoPath repeating table