Thursday, February 04, 2010

How to clear infopath repeating table data

public void ClearInfoPathTableData(string TABLE_PATH, List TableRowTitles)
{
int TempCount;

//Delete from last.
while (true)
{
TempCount = Root.Select(TABLE_PATH, NamespaceManager).Count;//Get the n.of rows to clear
if (TempCount == 1)
{
for (int count = 0; count < TableRowTitles.Count; count++)
{
XPathNavigator node = Root.SelectSingleNode(TABLE_PATH + "[1]/" + TableRowTitles[count], NamespaceManager);

if (node.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance"))
{
node.DeleteSelf();
}
node.SetValue("");
}
}
break;
}
Root.SelectSingleNode(TABLE_PATH + "[" + TempCount + "]", NamespaceManager).DeleteSelf();
TempCount = Root.Select(TABLE_PATH, NamespaceManager).Count;
}
}

No comments: