I have a form with a repeating section which contains a repeating section of its own. I would like to sort the form based on the field in the outer section, which worked until I made the other controls part of a repeating subsection.
I uploaded an image of the nested sections to help visualize the data (below).
Here is the code that worked before adding the repeating subsection:
private void SortRepeatingTable(string fieldName)
{
XPathNavigator mainDS = MainDataSource.CreateNavigator();
XPathNavigator aritems = mainDS.SelectSingleNode(
"/my:myFields/my:ARItems", NamespaceManager);
XmlReader reader = aritems.ReadSubtree();
DataSet ds = new DataSet();
ds.ReadXml(reader);
DataTable sortedTable = new DataTable();
if (ds.Tables != null && ds.Tables.Count > 0)
{
DataTable dt = ds.Tables[0];
sortedTable = dt.Copy();
sortedTable.Clear();
DataRow[] rows = dt.Select("", fieldName + " ASC");
foreach (DataRow row in rows)
{
sortedTable.Rows.Add(row.ItemArray);
}
}
ds.Tables.Clear();
ds.Tables.Add(sortedTable);
using (MemoryStream ms = new MemoryStream())
{
ds.WriteXml(ms);
ms.Position = 0;
XPathDocument doc = new XPathDocument(ms);
aritems.ReplaceSelf(doc.CreateNavigator());
ms.Close();
}
} Somehow I can't make the leap to taking my nested section along when I move the outer containers around. I would appreciate any ideas on this.