Locate the current row in a repeating table and update the fields through button click. - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Locate the current row in a repeating table and update the fields through button click.

Last post 01-14-2013 07:15 AM by Jimmy. 24 replies.
Page 1 of 2 (25 items) 1 2 Next >
Sort Posts: Previous Next
  • 07-20-2009 08:21 AM

    Locate the current row in a repeating table and update the fields through button click.

     Hi,

              I have a problem in my infopath (2007) form. Let me explain the scenario first. I have a repeating table, which is having 6 fields and 3(a) of them are hidden and i have 3(b) more fields in the form( not in the repeating table). 3(b) fields are located some where in the form. I have a button which is used to fill the 3(a) fields with 3(b) fields using the button click. If the button is clicked, 3(a) fields (hidden) must be filled with data from 3(b) fields. 

                     I will enter data into 3 visible fields in repeating table and 3(b) fields. If i click the button then 3(a) fields (hidden fields) should be filled with 3(b) data. For that i need to find the current row which i am filling. I am new to infopath  an VSTA . Can anybody help me with the code in C# to handle this event. Quick reply on this issue will be a great help to me.

    Thanks in Advance,

    Kalyan.

  • 07-20-2009 09:18 AM In reply to

    Re: Locate the current row in a repeating table and update the fields through button click.

     If you are using the InfoPath 2007 object model, then the current node of a repeating section would be e.Source, where e is the ClickedEventArgs parameter of the event handler.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-20-2009 09:50 AM In reply to

    Re: Locate the current row in a repeating table and update the fields through button click.

     Hi Jimmy,

                     Thanks for your quick response. Here is my data source

    -myFields
    - queryFields
    - tns: Z_RFC_PR_CREATE_EX
    - : IT_PRITEMS
    - item(Repeating)
    PLANT
    COST_CENTER
    PURCHASING_GROUP
    ORDER
                    G_L_ACCT
                    MATERIAL 
    - dataFields
    - tns: Z_RFC_PR_CREATE_EXResponse
    : EX_PRNO
    my: Plant
    my: CostCenter
    my: PurchasingGroup
     
    In the above data source ORDER, G_L_ACCT, MATERIAL are the fields in repeating table and PLANT, COST_CENTER, PURCHASING_GROUP are hidden fields. 
    On button click the data must be passed from  my: Plant, my: CostCenter, my: PurchasingGroup to hidden fields (PLANT, COST_CENTER, PURCHASING_GROUP).
    But the button should not be in the repeating table. It should be some where else in the form.
    When i click the button it should fill the hidden fields of the current row. 
    Here is the code that i wrote,
    I know this is the stupid code, Can you make the changes to this code if possible,
     


    public void CTRL37_6_Clicked(object sender, ClickedEventArgs e)

    {


    XPathNavigator xNav = MainDataSource.CreateNavigator();
    XPathNodeIterator xNode = xNav.Select("/dfs:myFields/dfs:queryFields/tns:Z_RFC_PR_CREATE_EX/IT_PRITEMS/item", NamespaceManager);
    while (xNode.MoveNext())

    {


    string PURCHASING_GROUP= xNode.Current.SelectSingleNode("/dfs:myFields/my:PurchasingGroup", NamespaceManager).Value;
    string PLANT = xNode.Current.SelectSingleNode("/dfs:myFields/my:Plants", NamespaceManager).Value;
    string COST_CENTER = xNode.Current.SelectSingleNode("/dfs:myFields/my:CostCenters", NamespaceManager).Value;

    }

    }

     

    Thanks,

    Kalyan.

     

  • 07-20-2009 09:54 AM In reply to

    Re: Locate the current row in a repeating table and update the fields through button click.

     If the button is not located in the repeating section, how do you intend for InfoPath to know what the "current" row is?  What do you consider to be the current row?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-20-2009 10:02 AM In reply to

    Re: Locate the current row in a repeating table and update the fields through button click.

    I am new to infopath.

                    Can't we use "e.source" if we are out side the repeating table. Is there any way to get the current row from the repeating table with out having the button with in the table. Because my requirement is like this. Any sugessions.

  • 07-20-2009 10:12 AM In reply to

    Re: Locate the current row in a repeating table and update the fields through button click.

     e.Source refers to the node of the section that contains the button.  If the button is in a repeating section, then e.Source is the repeating node, but if it is outside the repeating section, then e.Source will be a node outside the repeating data.

    As I already asked, how would you define "current row?"   I'm not clear on how you expect InfoPath to figure out which row you want to affect if the button is not inside the repeating section.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-20-2009 10:32 AM In reply to

    Re: Locate the current row in a repeating table and update the fields through button click.

     Actually my requirement is in that way. Yeah now it's clear for me we can't pick the current row if we use the button out side the table.

               I have another problem with views as well can you have a look at this link if you have time.

    http://www.infopathdev.com/forums/p/12589/44542.aspx#44542

    Thanks,

    Kalyan.

  • 07-20-2009 10:43 AM In reply to

    Re: Locate the current row in a repeating table and update the fields through button click.

     Can we update the last row in the repeating table by using the button out side the table?

  • 07-20-2009 06:03 PM In reply to

    Re: Locate the current row in a repeating table and update the fields through button click.

     Yes, certainly.  You just need to use the proper XPath.  If this is the correct path to your repeating nodes:

    /dfs:myFields/dfs:queryFields/tns:Z_RFC_PR_CREATE_EX/IT_PRITEMS/item

     Then you would want to use something like:

    XPathNavigator lastNode = xNav.Select("/dfs:myFields/dfs:queryFields/tns:Z_RFC_PR_CREATE_EX/IT_PRITEMS/item[last()]", NamespaceManager);

     Note the [last()] part at the end.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-21-2009 12:02 PM In reply to

    Re: Locate the current row in a repeating table and update the fields through button click.

    Can we control the data being passed from fields out side the repeating table to the hidden fields inside the repeating table using the "Insert item" in the table. My idea is to use changed event. I tried the "insert item" also, when i click insert item the data is getting transfered from fields to the freshly entered row, not to the earlier row.

    Can you help me on this.

    Thanks,

    Kalyan.

     

               

  • 07-21-2009 12:12 PM In reply to

    Re: Locate the current row in a repeating table and update the fields through button click.

    Our free qRules toolkit lets you programmatically insert items into a repeating section without code. Check out the Insert command. Unfortunately, qRules doesn't work if you have already have code in your form, but maybe you don't need to write code and can just test with a new form and qRules to see the technique.

    Patrick Halstead
    Project Manager at Qdabra
  • 07-21-2009 12:20 PM In reply to

    Re: Locate the current row in a repeating table and update the fields through button click.

     I have lot of code in the form, as you said it may not work.

  • 07-21-2009 06:42 PM In reply to

    Re: Locate the current row in a repeating table and update the fields through button click.

    What you can do is store a reference to the most recently added row, which you can access later when the button is clicked:

    XPathNavigator lastChanged;
    int lastRowCount;
    public void group2_Changed(object sender, XmlEventArgs e)
    {
        
    if (e.Site.Name.Equals("my:group2"))
         {
             
    int rowCount = e.Site.Select("../my:group2", NamespaceManager).Count;
             
    if (e.Operation == XmlOperation.Insert)
              {
                  
    if (rowCount > lastRowCount)
                   {
                        // my:group2 has been added
                        lastChanged = e.Site;
                   }
              }
             
    else if (e.Operation == XmlOperation.Delete)
              {
                  
    if (rowCount < lastRowCount)
                   {
                       
    // my:group2 has been removed
                       
    lastChanged = null;
                   }
              }
              lastRowCount = rowCount;
         }
    }

    Since removing a node could cause unpredictable behavior (e.g. if a row was added and then immediately deleted), I've opted to set the lastChanged variable to null if any row is removed, and you would need to check for this in the button's event handler.

    Since the changed event will fire with your repeating node as e.Site even if a node is inserted or deleted inside a repeating node, you will need to keep track of the number of repeating nodes you have and check whether the count has increased or decreased.  You can initialize this row count in the Loading event of the form:

    public void FormEvents_Loading(object sender, LoadingEventArgs e)
    {
         lastRowCount = MainDataSource.CreateNavigator().Select(
    "/my:myFields/my:group1/my:group2", NamespaceManager).Count;
    }

    Of course the XPaths and node names would be different in your case.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-23-2009 07:15 PM In reply to

    Re: Locate the current row in a repeating table and update the fields through button click.

     

     Hi Jimmy,

                    Thanks a lot for your help on this issue. I used a button inside the table to attach data to hidden fields and then removed the basic "insert row" option. Your post helped in another issue to calculate the row count and the row numbers accordingly.

    Thanks,

    Kalyan.
  • 12-07-2011 11:27 AM In reply to

    Re: Locate the current row in a repeating table and update the fields through button click.

    I am trying to use the e.source to get the value of a drop down field I have in my repeating section but it only works for the 1st instance of the repeating section   If I click the button in the 2nd or 3rd row it always grabs the value in the first row?  Any thoughts?

     

    public void TestButton_Clicked(object sender, ClickedEventArgs e)

    {

    XPathNavigator domNavTreatment = e.Source.CreateNavigator();

    string xhtmlRTFField = domNavTreatment.SelectSingleNode("//my:Treatment", NamespaceManager).InnerXml ;

    MessageBox.Show(xhtmlRTFField);  // this shows the value of the row as long as its the first???

    }

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