deleting rows from MULTIPLE repeating sections - InfoPath Dev
in

InfoPath Dev

deleting rows from MULTIPLE repeating sections

Last post 04-08-2013 06:27 AM by Hilary Stoupa. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 04-01-2013 08:46 AM

    deleting rows from MULTIPLE repeating sections

    Hello,

    I have a form that starts out with one repeating section with 10 rows by defeault. The user has the option of adding more repeating sections. I would like to remove any blank rows from these sections. If the form has only one repeating section tha I am able to successfully remove the blank rows with the following code

    XPathNavigator myNav = MainDataSource.CreateNavigator();

    XPathNodeIterator NodeIterator =

    myNav.Select("/my:myFFIM_base_table/my:Species_Records/my:SpeciesGroup/my:GROUP_1MM/my:GROUP_1MM_sub", NamespaceManager);

    XPathNavigator last = myNav.SelectSingleNode(

    "/my:myFFIM_base_table/my:Species_Records/my:SpeciesGroup/my:GROUP_1MM/my:GROUP_1MM_sub[" + NodeIterator.Count.ToString() + "]", NamespaceManager);

    while (NodeIterator.MoveNext())

    {

    myNode = NodeIterator.Current.CreateNavigator();

    if (CountOneM == "" && LengthOneM == "" && WeightOneM == "")

    {

    try {

    myNode.DeleteRange(last);}

    catch(Exception ex){}

    }}

    But if more sections are added than the DeleteRange line throws an error because last is null. So I am thinking I need to change the path of last XPathNavigator. Can someone please help me? I would greatly appreciate it.

    Thanks!!

                       

     

                   

     

  • 04-08-2013 06:27 AM In reply to

    Re: deleting rows from MULTIPLE repeating sections

     Is DeleteRange what you really want here? I mean, don't you just want to delete some rows where the fields inside are blank? I would loop through the nodes, add the blanks to an array, then use DeleteSelf to delete the items in the array.

    Read the remarks section in this link.

    I'd do something like this:

                XPathNavigator myNav = MainDataSource.CreateNavigator();

     

                XPathNodeIterator nodes = myNav.Select("/my:myFields/my:group1/my:group2", NamespaceManager); 

     

                List<XPathNavigator> deleteNodes = new List<XPathNavigator>(); 

     

                foreach (XPathNavigator node in nodes)

     

                {
                    if (node.SelectSingleNode("my:field1", NamespaceManager).Value == "")
                    {
                        deleteNodes.Add(node);
                    }
                }

     

                foreach (XPathNavigator deleteNode in deleteNodes)
                {
                    deleteNode.DeleteSelf();
                }

     

     

    Hilary Stoupa

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