Number and adding rows - InfoPath Dev
in

InfoPath Dev

Number and adding rows

Last post 05-12-2010 01:38 PM by aruna akella. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 05-10-2010 12:20 PM

    • arcad
    • Not Ranked
    • Joined on 05-10-2010
    • Posts 15

    Number and adding rows

    Hello all,

     I would like to know if it was possible to let the user type a number in a text box which would add that number of rows to an already existing repeating table. Lets say you type 25 and this action adds 25 rows to your repeating table in one shot.

     Thanks in advance for your help!

  • 05-10-2010 04:43 PM In reply to

    Yes. It's doable.

    Add this code to your text box changed event:

    XPathNavigator root = MainDataSource.CreateNavigator();

    XPathNavigator test = root.SelectSingleNode("/my:myFields/my:field4", this.NamespaceManager); // here field4 is the field where user enters a number to add rows dynamically.

    for (int i = 0; i < Int32.Parse(test.Value); i++)

    {

     InsertBlankRow(); // Write your logic to create a blank row(s) or row(s) with data

    }

    Attached a template file where I wrote a small sample to test it. Let me know if you have any questions.

    Aruna Akella
    Qdabra® Software / InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™
  • 05-11-2010 10:07 AM In reply to

    • arcad
    • Not Ranked
    • Joined on 05-10-2010
    • Posts 15
    I cannot open the sample. It says this form cannot be opened because it requires the domain permission level and it currently has restricted permission. To fix this problem, open the form from the location it was published to.
  • 05-11-2010 10:13 AM In reply to

    Sorry about that. Can you try now?

    Aruna Akella
    Qdabra® Software / InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™
  • 05-11-2010 10:28 AM In reply to

    • arcad
    • Not Ranked
    • Joined on 05-10-2010
    • Posts 15

    Thanks.

     Here is my code:

     

    XPathNavigator root = MainDataSource.CreateNavigator();

    XPathNavigator test = root.SelectSingleNode("/my:myFields/my:Software/my:field1", this.NamespaceManager);

    for (int i = 0; i < Int32.Parse(test.Value); i++)

    {

    XPathNavigator root2 = MainDataSource.CreateNavigator();

    XPathNavigator group = root2.SelectSingleNode("/my:myFields/my:Software/my:group53/my:"RepeatingTable"[last()]", this.NamespaceManager);

    XPathNavigator NewRow = group.Clone();

    NewRow.InsertAfter(group);

    }

     

    The error is get that A calculation in the form has not been completed. The number of calculations used for a single action exceeded the maximum limit. The error is pointing to the "NewRow.InsertAfter(group)" line.

     

    Any ideas? Thanks.

  • 05-11-2010 10:43 AM In reply to

    Why don't you use the XmlWriter object that is returned by the AppendChild method of the XPathNavigator objcet to add a new row to a repeating tbl?

    Can you post your template? - so that I can look at it later today....

     

    Aruna Akella
    Qdabra® Software / InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™
  • 05-11-2010 11:46 AM In reply to

    • arcad
    • Not Ranked
    • Joined on 05-10-2010
    • Posts 15

    There it is. Thanks!

  • 05-11-2010 09:15 PM In reply to

    Attached the modified template - I used XmlWriter object to add a new row. Regarding the error you saw, can you please go through this post ? 

     

    Aruna Akella
    Qdabra® Software / InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™
  • 05-12-2010 01:38 PM In reply to

    This issue is resolved via e-mail.

    Here is the piece of code to add rows dynamically to a repeating table via code (note: change the xpath)

               private void InsertBlankRow()
            {
                string myNamespace = NamespaceManager.LookupNamespace("my");
                using (XmlWriter writer = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Group53", this.NamespaceManager).AppendChild())
                {
                    writer.WriteStartElement("Software_Serials", myNamespace);
                    writer.WriteElementString("Software_Serial", myNamespace, string.Empty);
                    writer.WriteElementString("Machines_Lookup", myNamespace, string.Empty);
                    writer.WriteEndElement();
                    writer.Close();
                }
            }
     
            public void Software_Purchased_Licenses_Changed(object sender, XmlEventArgs e)
            {
                // Write your code here to change the main data source.
                XPathNavigator root = MainDataSource.CreateNavigator();
                XPathNavigator test = root.SelectSingleNode("/my:myFields/my:Software_Purchased_Licenses", this.NamespaceManager);
                for (int i = 0; i < Int32.Parse(test.Value); i++)
                {
                    InsertBlankRow();
     
                }
            }

     

    Aruna Akella
    Qdabra® Software / InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™
    Filed under:
Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.