Occurs after changes to a form's underlying XML document have been made but before the changes have been accepted.
Assembly: Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)
The Changing event is not meant to be instantiated by the developer in form code. When you add an event handler to your form template from the design mode user interface, Microsoft InfoPath generates code in the InternalStartup method of your form code file using the EventManager class and the member of the XmlEvent class to bind document-level events to their event handlers. For information on how to add event handlers in InfoPath design mode, see How to: Add an Event Handler.
The Changing event is bound using the XmlChangingEventHandler delegate.
This event handler allows users to cancel an operation.
During the Changing event, the form's underlying XML document is placed in read-only mode. If the XmlChangingEventArgs.CancelableArgs.Cancel property is set to true, InfoPath rejects the changes that were made and a message box is displayed to the user. If an error occurs in the code for the Changing event, InfoPath rejects the changes and restores the data to its previous state.
It is best to avoid switching views during the Changing event; changes have not yet been accepted, and switching to another view may result in an error.
This type or member can be accessed only from code running in forms opened in Microsoft InfoPath Filler.
In the following example, when a change is made to field2, the Changing event is raised and a FormError object for field1 is added to the form's FormErrorCollection using the Add method of the FormErrorCollection class.
This associates an error message with field1. The string passed as the message parameter of the Add method is displayed in a screen tip when the user hovers over field1. When the user right-clicks field1 and then clicks Full error description, InfoPath displays the full error message including the string passed as the messageDetails parameter of the Add method.
Public Sub field2_Changing(ByVal sender As Object, _ ByVal e As XmlChangingEventArgs) Dim errNode As XPathNavigator = Me.CreateNavigator(). _ SelectSingleNode("/my:myFields/my:field1", NamespaceManager) Me.Errors.Add(errNode, "Field2Changing", _ "The Changing event occurred for Field2.", _ "Changes were made, but have not yet been accepted.") End Sub