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.
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.
There are two event handlers that you can add to a row of a repeating table:
So how do you add an event to a row of a repeating table? Here's how:
- Create a new InfoPath form.
- 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.
- 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.
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.
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.
Related InfoPath Articles:
- Auto-fill a repeating table with data from a SharePoint list when a row is inserted
- Count the total amount of sections in a Repeating Section in InfoPath on insert or delete
- 4 Ways to programmatically add a row to a repeating table in InfoPath
- Programmatically delete all of the rows of a repeating table in InfoPath
- Programmatically delete the first row of a repeating table in InfoPath