Programmatically execute code when a repeating table row is inserted or deleted

Learn how to add events to rows of a repeating table instead of its fields.

ADVERTISEMENTS

A technique which I've not often seen explained anywhere on the web is how to use events on the rows of a repeating table instead of its fields.

So in this article I'll tell you how you can add an event to a repeating table so that code can be executed when a repeating table row is either added or deleted. I'll then use this technique in a future post to demonstrate how you can retrieve the number of the current row of a repeating table.

Note: To be able to write code in InfoPath 2007, you'll have to install InfoPath with VSTA or use Visual Studio. This article assumes that you have installed InfoPath with VSTA.

There are two event handlers that you can add to a row of a repeating table:

  1. Validating Event
  2. Changed Event

So how do you add an event to a row of a repeating table? Here's how:

  1. Create a new InfoPath form.
  2. From the Controls pane, drag-and-drop a Repeating Table on the form. The repeating table will contain 3 columns by default and the rows will be represented by the group2 repeating node of the repeating table.
  3. From the Data Source pane, right-click the group2 node (this represents the rows), and then select Programming > Changed Event from the context menu that appears. This will add the following VB.NET code for you Public Sub group2_Changed(ByVal sender As Object, ByVal e As XmlEventArgs)
    ' Write your code here to change the main data source.
    End Sub

Now you can write code in the event handler so that that code is executed when a row is inserted or deleted. You can also add functionality to distinguish between insert and delete operations by testing whether the e.Operation property is equal to XmlOperation.Insert or XmlOperation.Delete.

 
 Subscribe for updates via RSS or Email

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent of S.Y.M. Wong-A-Ton. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author, S.Y.M. Wong-A-Ton.

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners
InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013
InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners
InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010
InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers
InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services


Related InfoPath Articles:

ADVERTISEMENTS

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners

InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013

InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners

InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010

InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers

InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services