Populate repeating table row - InfoPath Dev
in

InfoPath Dev

Populate repeating table row

Last post 12-14-2011 07:36 AM by jaxkookie. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 12-12-2011 04:04 PM

    Populate repeating table row

    I am looking for a way with a button click event to copy data from several fields to a new row in a repeating table row. I was hopping I did not have to identify every source field and every target field. For now, testing, I have 3 text fields. once I add values to these fields I want to cluck a button, copy these valuse and add it to a repeating table.

     

    Can this be done? any help appreciated.

    Kind regards,
    Larry
  • 12-13-2011 05:37 AM In reply to

    Re: Populate repeating table row

    I have come up with some what of a working solution. The problem now is my first row remains blank. here is what I have:

    my form structure:

    myFields
     Master1
     Master2
     Master3
     Chld
       Child
          Child1
          Child2
          Child3
    

     

    Master1 will set Child1 and so on.

    This is the button code:

    public void AddData_Clicked(object sender, ClickedEventArgs e)
            {
                XPathNavigator Master1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Master1", NamespaceManager);
                XPathNavigator Master2 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Master2", NamespaceManager);
                XPathNavigator Master3 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Master3", NamespaceManager);
                XPathNavigator Child = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Chld/my:Child", NamespaceManager);
                
                XPathNavigator navigator = MainDataSource.CreateNavigator();
                navigator.MoveToFollowing(XPathNodeType.Element);
    
                XPathNavigator sectionNode = navigator.SelectSingleNode("/my:myFields/my:Chld", NamespaceManager);
    
                string ns = sectionNode.NamespaceURI;
    
                XmlWriter writer = sectionNode.AppendChild();
                DeleteNil(Child);
                writer.WriteStartElement("my", "Child", ns);
                writer.WriteElementString("my", "Child1", ns, Master1.Value.ToString()); 
                writer.WriteElementString("my", "Child2", ns, Master2.Value.ToString());
                writer.WriteElementString("my", "Child3", ns, Master3.Value.ToString());
                writer.WriteEndElement();
    
                writer.Close();         
             }

    how can I get the code to write to the first row or eliminate the first row completely?

    Kind regards,
    Larry
  • 12-13-2011 08:00 AM In reply to

    Re: Populate repeating table row

    You could not include the row by default. Tools / Default Values from IP 2007 - the Data tab on the ribbon in IP 2010. Just deselect the checkbox, and the row won't be included. Of course, it appears in your code you are creating a variable that uses the XPath to that node (although it doesn't seem to be used?) - if you don't include the node by default when the form is created, that Child variable will be null.
    Hilary Stoupa

  • 12-13-2011 08:56 AM In reply to

    Re: Populate repeating table row

    Thanks Hilary. I was finaly able to return a solution. I am incrementing a field with each button click. So on that field change event I am removing the first row, Using a rule to hide the first row by default. So now I am trying to add a button to each row that will allow me to copy the data in that row and write it back to my Master fields. Seems I keep getting an error because of"nil".

    public void AddData_Clicked(object sender, ClickedEventArgs e)
            {
    
                XPathNavigator Master1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Master1", NamespaceManager);
                XPathNavigator Master2 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Master2", NamespaceManager);
                XPathNavigator Master3 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Master3", NamespaceManager);
                //XPathNavigator index = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:index", NamespaceManager);
               
                        XPathNavigator navigator = MainDataSource.CreateNavigator();
                        navigator.MoveToFollowing(XPathNodeType.Element);
    
                        XPathNavigator sectionNode = navigator.SelectSingleNode("/my:myFields/my:Chld", NamespaceManager);
    
                        string ns = sectionNode.NamespaceURI;
    
                        XmlWriter writer = sectionNode.AppendChild();
                        writer.WriteStartElement("my", "Child", ns);
                        writer.WriteElementString("my", "Child1", ns, Master1.Value.ToString()); 
                        writer.WriteElementString("my", "Child2", ns, Master2.Value.ToString());
                        writer.WriteElementString("my", "Child3", ns, Master3.Value.ToString());
                        writer.WriteElementString("my", "ChildIndex", ns, F8.Value.ToString());
                        writer.WriteEndElement();
    
                        //writer.Flush();
                        writer.Close();
                 
            }
    
            public void index_Changed(object sender, XmlEventArgs e)
            {
                XPathNavigator CI = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Chld/my:Child/my:ChildIndex", NamespaceManager);
                XPathNavigator CIParent = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Chld/my:Child", NamespaceManager);
                     
                if (Convert.ToInt32(CI.Value) == 0)
                {
                    CIParent.DeleteSelf();
                    
                }
    
            }
    
            public void EditItem_Clicked(object sender, ClickedEventArgs e)
            {
               
                //XPathNavigator nodeToClone = e.Source;
                //nodeToClone.Clone().InsertAfter(e.Source);
                XPathNavigator Master1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Master1", NamespaceManager);
                XPathNavigator Master2 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Master2", NamespaceManager);
                XPathNavigator Master3 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Master3", NamespaceManager);
                XPathNavigator Child1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Child1", NamespaceManager);
                XPathNavigator Child2 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Child2", NamespaceManager);
                XPathNavigator Child3 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Child3", NamespaceManager);
    
                Master1.SetValue(Child1.Value);
                Master2.SetValue(Child2.Value);
                Master3.SetValue(Child3.Value);
           
            }
    seems my Child values are null. Is there a way to copy fields in a selected row and set the values to non-repeating fields?
    Kind regards,
    Larry
  • 12-14-2011 07:36 AM In reply to

    Re: Populate repeating table row

    I got it! I was over complicating it. I scrapped half the code and restarted. I have one button the will add to the repeating table first row, or append additional rows. Then I added a button to the table row. Onclick I run rules to update my master with current() row data, and delete the current  row. works perfectly in client and browser.

     

    thanks again

    Kind regards,
    Larry
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.