Loop through a repeating table in a repeating section - InfoPath Dev
in

InfoPath Dev

Loop through a repeating table in a repeating section

Last post 07-31-2008 10:32 AM by nbkkjw1. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 07-03-2008 12:46 PM

    Loop through a repeating table in a repeating section

    Hello:

    I have a repeating section with a repeating table. In my repeating table a had a button that launch a windows form that loop through the repeating table and it on the DataGridView in my windows form.

    But when I insert a new section and click the button in that new section, it also loop through the first repeating section.

    How do I this in code to prevent from looping from other repeating section?

    here is my code:

          ======================================

            'Module.VB

            Public  ClientList as new  Datatable()

           ======================================

            'Form Code

             Private Sub GetClientList()

                If ClientList.Columns.Count = 0 Then

                    ClientList.Columns.Add("ClientNo")
                    ClientList.Columns.Add("MatterNo")
                    ClientList.Columns.Add("Percentage")

                    Dim dnav As XPathNavigator = MainDataSource.CreateNavigator()
                    Dim rows As XPathNodeIterator = dnav.Select("/my:ExpenseAccount/my:LLPGroup/my:LLPExpenseGroup/my:ItemExpenseGroup/my:ClientGroup/my:ItemClientGroup", NamespaceManager)

                    While rows.MoveNext()

                        Dim ClientNo As String = rows.Current.SelectSingleNode("my:ClientNo", NamespaceManager).Value
                        Dim MatterNo As String = rows.Current.SelectSingleNode("my:MatterNo", NamespaceManager).Value
                        Dim Percents As String = rows.Current.SelectSingleNode("my:ExpensePercentage", NamespaceManager).Value
                        Dim row As DataRow

                        row = ClientList.NewRow()
                        row("ClientNo") = ClientNo
                        row("MatterNo") = MatterNo
                        row("Percentage") = Percents

                        ClientList.Rows.Add(row)

                    End While

                End If

            End Sub

     

     

     

  • 07-06-2008 06:15 AM In reply to

    Re: Loop through a repeating table in a repeating section

    Hello:

    Your node iterator will go through all the ItemClientGroup nodes, regardless of the section they are in. The Clicked event for an InfoPath button has two arguments:

    ByVal sender As Object, ByVal e As ClickedEventArgs

    You can use e to get a node in the group the button is located in. For example, if I have a repeating section that has a single text field and a button in it, I could use the following code to get a message box to show me the value in the field in the section that the button is clicked in:

    Public Sub CTRL6_6_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
        
    Dim field As String = e.Source.SelectSingleNode("my:field1", NamespaceManager).Value
         MessageBox.Show(field)
    End Sub

    So, I can insert a few repeating sections, type different text into my field in each one, and when I click the button in each section, my message box will show me the value of the field in that section. I think you might be able to use e.Source.SelectSingleNode to select the correct ItemClientGroup, and pass that to your GetClientList method instead of using the node iterator.

    Hilary Stoupa

  • 07-07-2008 08:33 AM In reply to

    Re: Loop through a repeating table in a repeating section

    Thanks for the reply... I'll try your advise.

    :)

  • 07-07-2008 09:05 AM In reply to

    Re: Loop through a repeating table in a repeating section

     It works...  THanks!!!

     Here is my new code...

     

            Public Sub ButtonGetBreakDown_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

                GetClientList(e)
     

                ......

            End Sub

     

            Private Sub GetClientList(ByVal e As ClickedEventArgs)

                If ClientList.Columns.Count = 0 Then

                    ClientList.Columns.Add("ClientNo")
                    ClientList.Columns.Add("MatterNo")
                    ClientList.Columns.Add("Percentage")

                    Dim it As XPathNodeIterator = e.Source.SelectAncestors(XPathNodeType.Element, False)
                    it.MoveNext()
                    Dim nodeParent As XPathNavigator = it.Current
                    Dim siblings As XPathNodeIterator = nodeParent.SelectChildren(XPathNodeType.Element)

                    For Each sibling As XPathNavigator In siblings

                        Dim ClientNo As String = sibling.SelectSingleNode("my:field1", NamespaceManager).Value
                        Dim MatterNo As String = sibling.SelectSingleNode("my:field2", NamespaceManager).Value
                        Dim row As DataRow

                        row = ClientList.NewRow()
                        row("field1") = ClientNo
                        row("field2") = MatterNo

                        ClientList.Rows.Add(row)

                    Next


                End If

            End Sub

  • 07-08-2008 08:59 AM In reply to

    Re: Loop through a repeating table in a repeating section

    I thought I've already fixed my problem....

    I forgot to mention that I have to repeating tables in my repeating section.

    One of the repeating table contain the button that iterates the items of the other repeating table.

    In my understanding "e.Source" only works within the current repeating table.

    But how do you reference another repeating table even though you fire the event (click) from a different repeating table?

    Thanks

    J

     

    BTW: The code that I posted above works only if I only have 1 repeating table in a repeating section.

     

     

     

     

  • 07-08-2008 01:08 PM In reply to

    Re: Loop through a repeating table in a repeating section

    I'm afraid I'm having a little trouble visualizing exactly what you have going on. You have two repeating tables in a repeating section? and when you click a button in one of the tables, you want to iterate through all of the rows of another table? Is each table connected to it's own group in the data source? If nodeParent is referring to the repeating section, you will select everything in it with SelectChildren(XPathNodeType). Perhaps try SelectChildren(String,String) and input the xpath to the correct repeating table? For more information, see: http://msdn.microsoft.com/en-us/library/yx5btkz8.aspx

    Hilary Stoupa

  • 07-31-2008 10:32 AM In reply to

    Re: Loop through a repeating table in a repeating section

    I have read the threads and it appears that this may close solve my problem, but since I am new to this, I have to ask.. I do not want to make this any more complex than it has to be.

     

    I have a repeating table with five columns and a button in one of the columns. The user selects from a drop-down list and selects a name. Based on the selection the remaining columns are populated. One of the columns is populated with an email address. When all of the row/names have been entered, the user can go to any row and click the button in that row, to send an email to the address in that row. It all works, except for the email. If I use eval I get all of the emails not just the one. If I reference the email, I will only get the first row email address, no matter what row that I am in.

     

    I have tried other commands and syntax but none will work. I tried "current", postion(), eval. I get either syntax errors or a error returned. I cannot seem to only pick out the email for the row that I am in.

     

    Any help would be appreciated, thanks.

     

    Ken

     

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