Sorting Nested Repeating Sections - InfoPath Dev
in

InfoPath Dev

Sorting Nested Repeating Sections

Last post 03-13-2013 02:09 PM by Hilary Stoupa. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 02-27-2013 01:50 PM

    • echotrain
    • Not Ranked
    • Joined on 02-27-2013
    • Nashville TN
    • Posts 4

    Sorting Nested Repeating Sections

    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.
    

  • 03-13-2013 02:03 PM In reply to

    • echotrain
    • Not Ranked
    • Joined on 02-27-2013
    • Nashville TN
    • Posts 4

    Re: Sorting Nested Repeating Sections

    This was eventually solved

  • 03-13-2013 02:09 PM In reply to

    Re: Sorting Nested Repeating Sections

     Wonderful - sorry no one had any suggestions / help for you. I'm glad you got it sorted. Care to post your solution?

    Hilary Stoupa

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.