EN
Konten ini tidak tersedia dalam bahasa Anda dan berikut adalah versi bahasa Inggris.

XmlEvent.Changing event

Occurs after changes to a form's underlying XML document have been made but before the changes have been accepted.

Namespace:  Microsoft.Office.InfoPath
Assembly:  Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)

public abstract event XmlChangingEventHandler Changing

ExceptionCondition
InvalidOperationException

The developer attempted to bind the event in some location other than the InternalStartup method.

InvalidOperationException

The developer attempted to bind the event to a node in secondary data source. This event is not supported for secondary data sources.

Important noteImportant

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.

NoteNote

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 void field2_Changing(object sender, XmlChangingEventArgs e)
{
   XPathNavigator errNode = 
      this.CreateNavigator().SelectSingleNode("/my:myFields/my:field1", 
      NamespaceManager);
   this.Errors.Add(errNode, "Field2Changing", 
      "The Changing event occurred for Field2.", 
      "Changes were made to Field2, but have not yet been accepted.");
}
Tampilkan:
© 2014 Microsoft