Repeating tables are always initialized with an empty first row, which you have to either remove or fill when programmatically adding rows to a repeating table. The XMLWriter object is used to write XML and not change existing XML, so filling the first row with data is not possible using this object.
There are two ways to solve this issue:
- If you have a loop that you use to populate the repeating table with rows, make sure you use the first item in the loop to fill the first row with data, and then continue looping through the other items and use the AppendChild method to create new rows in the repeating table. You can use code similar to the following code to populate the first row of a repeating table:
XPathNavigator mainDOMNav = MainDataSource.CreateNavigator();
XPathNavigator groupNav = mainDOMNav.SelectSingleNode("/my:myFields/my:group1/my:group2[1]",
NamespaceManager);
groupNav.SelectSingleNode("my:field1", NamespaceManager).SetValue("Cell 1");
groupNav.SelectSingleNode("my:field2", NamespaceManager).SetValue("Cell 2");
groupNav.SelectSingleNode("my:field3", NamespaceManager).SetValue("Cell 3");
- Loop through all your items, use AppendChild to create new rows in the repeating table, and then afterwards delete the first row by using code similar to the following code:
// Delete first row
XPathNavigator mainDOMNav = MainDataSource.CreateNavigator();
XPathNavigator groupNav = mainDOMNav.SelectSingleNode("/my:myFields/my:group1/my:group2[1]",
NamespaceManager);
if (String.IsNullOrEmpty(groupNav.SelectSingleNode("my:field1", NamespaceManager).Value)
&& String.IsNullOrEmpty(groupNav.SelectSingleNode("my:field2", NamespaceManager).Value)
&& String.IsNullOrEmpty(groupNav.SelectSingleNode("my:field3", NamespaceManager).Value))
{
groupNav.DeleteSelf();
}
Update (07 Jan 2009):
Since posting this, I’ve written more articles about deleting rows in repeating tables:
- Programmatically delete all of the rows of a repeating table in InfoPath
- Programmatically delete the first row of a repeating table in InfoPath
You might also be interested in:

Comments to this post were closed 30 days after it was published.