Programmatically delete the first row of a repeating table in InfoPath
Learn how to use C# or Visual Basic code to programmatically delete the first row of a repeating table in InfoPath.
You have a repeating table in which the first row contains empty values, so you want to programmatically delete this row.
Use the DeleteSelf() method of the XPathNavigator object to delete the first row in a repeating table.
You can achieve this functionality as follows:
- Create a new blank InfoPath form template, and add a Repeating Table and a Button control to it.
Figure 1. The the form template in Design mode.
The Main data source is shown in the following figure:
Figure 2. The Main data source of the form template.
- Double-click the Button control to open its Properties dialog box.
- On the Button Properties dialog box, click Edit Form Code to add a Clicked event handler for the button.
Add the following C# code to the Clicked event:
// Retrieve the first row of the repeating table
XPathNavigator domNav = MainDataSource.CreateNavigator();
XPathNavigator itemNav = domNav.SelectSingleNode(
// Delete the row
if (itemNav != null)
Or add the following Visual Basic code to the Clicked event:
' Retrieve the first row of the repeating table
Dim domNav As XPathNavigator = MainDataSource.CreateNavigator()
Dim itemNav As XPathNavigator = domNav.SelectSingleNode( _
' Delete the row
If itemNav IsNot Nothing Then
Note: You can use the Copy XPath functionality in the Data Source pane (also see Programmatically retrieve the value of an InfoPath form field using .NET code) to find out what the XPath expression of the group2 node should be. Then you can add the XPath expression filter  to retrieve the first row of the repeating table.
- Save your work, build the code, and test the form.
Now when you click the button, the first row of the repeating table will be deleted.
Related InfoPath Articles:
- Programmatically delete all of the rows of a repeating table in InfoPath
- How to loop through items in a repeating table in InfoPath 2007
- Programmatically retrieve the value of an InfoPath form field using .NET code
- Programmatically retrieve the value of another field in the same row of a repeating table in InfoPath 2007
- Programmatically hide the first row of a repeating table in InfoPath
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.