Friday, July 11, 2008

Programmatically adding Rows in a Repeating Table of InfoPath Forms

Its very easy to programmatically add rows in a repeating table of InfoPath Forms. Just follow these steps:

  1. Add a repeating table to your InforPath Form.
  2. Select the Repeating table and while selecting it come on Tasks Pane, and click Data Source.
  3. You will see the selected Repeating table group in Data Source, right click on the repeating table group and copy the XPath. Save this Path somewhere.
  4. Now Add a button on You InfoPath form having text "Add Rows".
  5. Right click that button and click programming --> Changed Event.
  6. A separate C# code file will open in Visual Studio with the changed Event Registered.
  7. Write this code in the Event Handler Function. And that is it! You have learned to programmatically add rows in Repeating table.
Code:
"NODEPATH" is the XPath of the Repeating table you have copied
XPathNavigator Group = MainDataSource.CreateNavigator().SelectSingleNode("NODEPATH", NamespaceManager);
XPathNavigator newRow = Group.Clone();
newRow.InsertAfter(Group);

Hope this will be helpful for you. You are most welcome for Queries and Suggestions.

6 comments:

Anonymous said...

Do you know how to programmatically insert a repeating section? I have 3 checkboxes. I want the repeating section to be inserted when a checkbox is checked. Which means only up to 3 repeating sections can be inserted. When unchecked the inserted section is deleted. I asked my IT dept and they don't know. I was hoping other experts out there can help me.

Munazzah said...

One way is to add three optional section to your form and in each optional section add repeating section.
another way is to add three repeating sections and add Conditional formmatting on each section i.e. when checkbox1 is equal to "false" hide this section.

hope this will help you.

jaxkookie said...

been a while since this was active. I am trying to copy data from 3 text fields and insert that data into a new repeating table row. any suggestions?

jaxkookie said...

I am trying to copy data from 3 fields and add the values into a new repeating table row. any suggestions

Andrea said...

electronic signature for sharepoint
Wow. I was trying to do the same task but didn't find any solution. Thanks to you for explaining the correct way.

Newbee said...

Thank you so much !!! I spent the morning trying to understand, you are the only clear, neat one I found!