Deleting rows from table - InfoPath Dev
in

InfoPath Dev

Deleting rows from table

Last post 09-10-2009 08:40 AM by Alec Pojidaev. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 06-04-2009 01:15 AM

    • ilya.mim
    • Not Ranked
    • Joined on 10-18-2008
    • Russia
    • Posts 8

    Deleting rows from table

    Hi, 

    Can you give me advice how can I delete rows from a table?

    I have the folloing structure:

    myFields

    -> group1 (section)

    ----> group2

    --------> group3 (repeating table)

    -------------> field1

    -------------> field2

    -------------> field3

    I need to delete all rows from group3. Then I add a new set of rows.

    I used next code but it does not work.

                String xpath = "/my:myFields/my:group1/my:group2/my:group3";
                XPathNodeIterator navigator = MainDataSource.CreateNavigator().Select(xpath, NamespaceManager);
                int count = navigator.Count;
                if (count > 0)
                {
                    while (navigator.MoveNext())
                    {
                        navigator.Current.DeleteSelf();
                    }
                }

     

    Can you explain also why Infopath insert the element Group2 in the document structer between the section  Group1 and the repeating table Group3?

     

    Thanks

  • 06-04-2009 06:27 AM In reply to

    Re: Deleting rows from table

    Please try this:

                String xpath = "/my:myFields/my:group1/my:group2";
                XPathNavigator navigator = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager);

                string myNamespace = NamespaceManager.LookupNamespace("my");
                    while (navigator.MoveToChild("group3", myNamespace))
                    {
                        navigator.DeleteSelf();
                    }

    I would imagine InfoPath creates the node structure like that because having repeating nodes all grouped under their own parent makes them easier to manage, but there is nothing stopping you from setting up your data source the way you want it and then binding a repeating table to it afterwards.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-06-2009 01:04 PM In reply to

    • ilya.mim
    • Not Ranked
    • Joined on 10-18-2008
    • Russia
    • Posts 8

    Re: Deleting rows from table

    Thanks Jimmy for your response.

    I decided my trouble I used something like this:

                xpath = "/my:myFields/my:group1/my:group2/my:group3";            

                XPathNodeIterator navigator = MainDataSource.CreateNavigator().Select(xpath, NamespaceManager);
                int count = navigator.Count;

                if (count > 0)
                {

                       String xpath = "/my:myFields/my:group1/my:group2/my:group3[1]";
                       XPathNavigator first = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager);
                       String xpath = "/my:myFields/my:group1/my:group2/my:group3[" + navigator.Count.ToString() + "]";
                       XPathNodeIterator last= MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager);

                       first.DeleteRange(last);   
                }

    But I'll also try your variant when I see my infopath project on Monday.

    Concerning my structure I deleted the group2 and other groups like the group2 which Infopath created in my project:

    myFields

    -> group1 (section)

    --------> group3 (repeating table)

    -------------> field1

    -------------> field2

    -------------> field3

    --------> group5 (repeating table)

    -------------> field4

    But I have doubt about my decision. I have to programmatically creates rows in a repeating tabel. Can I do this correct if I have deleted grouped nodes?

     

  • 06-08-2009 07:40 AM In reply to

    Re: Deleting rows from table

    If you're programmatically adding rows to the table, I would recommend against the structure you just described.  It will probably create the extra work of making sure that all of the group5s are inserted after all of the group3s.  I'd recommed putting the repeating groups under their own non-repeating parents.

     I'd also recommend using more descriptive names for your fields and groups.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.