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

Applies to: InfoPath 2007

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


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.


Related InfoPath Articles:


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. 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.