Repeating Section Count - InfoPath Dev
in

InfoPath Dev

Repeating Section Count

Last post 02-20-2009 01:58 PM by Patrick Halstead. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 02-13-2009 04:34 PM

    Repeating Section Count

    I have a repeating control and I would like the user to specify how many times the control should repeat. I just have a textbox and a button and I am trying to get the rule working for the button, but I can only set a field's value. Is there a way, using rules, that I could set the count(repeating_section) to what is typed in the textbox?

     Thanks,
    Igor

  • 02-15-2009 10:12 PM In reply to

    Re: Repeating Section Count

    Hi,

    Add the default value to the text box using the following steps. So that when the user inserts/deletes the row from the repeating section, it automatically updates the value.

    1. Go to the text box properties.

    2. Click on fx button beside the Value box.

    3. Select the Count function.

    4. In that enter the xpath of the repeating section.

    The expression should look like

    count(/my:myFields/my:group1/my:group2)

     

    here /my:myFields/my:group1/my:group2 is the repeating section xpath.

     

    Swathip
    www.ggktech.com
  • 02-15-2009 10:37 PM In reply to

    Re: Repeating Section Count

    Igor, there is no way to do what you described using rules, though it is easy enough if you use code.

    Please let me know if you would like to go that route, and what type of code (JScript, C#, VB) you would like to use.

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

    Re: Repeating Section Count

    Jimmy,

     I would like to do this in C#.

     Thanks,
    Igor

  • 02-17-2009 05:25 PM In reply to

    Re: Repeating Section Count

    Ok, please try putting this code in the event handler for a button.  You will need to change the underlined parts.  The first underlined part corresponds to the path of the field where the user will enter the count, and the second is the path of the repeating group on your form:

    XPathNavigator mainDataNavigator = MainDataSource.CreateNavigator();
    // select the field where the user is entering the number
    XPathNavigator countField = mainDataNavigator.SelectSingleNode("/my:myFields/my:field1", NamespaceManager);
    int requestedCount;
    // check that the value of the field is a valid number and parse it if it is
    if (Int32.TryParse(countField.Value, out requestedCount))
    {

         // determine the number of rows already in the table
         int currentCount = mainDataNavigator.Select("/my:myFields/my:group1/my:group2", NamespaceManager).Count;
         // if the table already has as many as, or more rows than the user requested, show an error
         if (currentCount >= requestedCount)
         { 
              MessageBox.Show(string.Format("The table already has {0} rows.", currentCount));
        
    }
         else
         {
             
    // add rows to the table until the total number of rows is the requested number
              for (; currentCount < requestedCount; currentCount++)
              {
                  
    // The xmlToEdit value ("group2_1" here) can be found in the repeating
                   // table's properties on the Advanced tab
                   CurrentView.ExecuteAction(ActionType.XCollectionInsert, "group2_1");
             
    }
        
    }
    }
    else
    {
        
    // If the entered number could not be parsed, show an error.
         MessageBox.Show("Please enter a valid number.");

    }
    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-19-2009 01:49 PM In reply to

    Re: Repeating Section Count

    Thanks Jimmy, this works well.

  • 02-20-2009 11:05 AM In reply to

    Re: Repeating Section Count

    Jimmy,

     Is there any way to do this in a browser-only enabled form? I'd like to create a 2nd version.

     Igor

  • 02-20-2009 01:58 PM In reply to

    Re: Repeating Section Count

    Hi Igor92128,

    You can browser-enable a form with code but it requires an extra activation when publishing to SharePoint (due to security restrictions of adding code).  

    Patrick Halstead
    Project Manager at Qdabra
Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.