DocContextChangeEvent Object

Microsoft Office InfoPath

DocContextChangeEvent Object

An event object that is used during a Microsoft Office InfoPath 2003 context change event. The DocContextChangeEvent object provides a number of properties that can be used within a context change to programmatically interact with the data in a form's underlying XML document, to provide contextual feedback to the user, or to perform actions for the user.

Remarks

The DocContextChangeEvent object is passed as a parameter to the OnContextChange event.

The DocContextChangeEvent object is used to get information about the XML Document Object Model (DOM) node that is the current context of the form's underlying XML document. In addition, it provides information about the type of context change and whether the change happened in response to an undo or redo operation performed by the user.

As described in the OnContextChange event topic, the Type property returns only the value "ContextNode" for context changes in Microsoft InfoPath 2003 Service Pack 1. Nevertheless, if code in an event handler performs actions that depend on current functionality, that code should still be designed to check the value of the Type property, because future versions of InfoPath may use different values for different context changes.

Note  This object model member is not supported when the Disable Service Pack features option on the Advanced tab of the Options dialog box in InfoPath is selected or when Microsoft Office 2003 Service Pack 1 or later is not installed. Any form that implements this object model member in its code will generate an error message if it is opened in InfoPath when service pack features are disabled or unavailable.

Using the DocContextChangeEvent object

When the IsUndoRedo property of the DocContextChangeEvent object is True, the context change was caused by an undo or redo operation rather than an explicit user context change. Operations performed in the OnContextChange event handler that modify the XML DOM should be avoided in response to undo or redo actions, because they may interfere with the user's intention to revert data to a previous state.

Example

In the following example, a node named lastChanged is updated in response to context changes:

    function XDocument::OnContextChange(eventObj) 
{
    if ( eventObj.Type == "ContextNode" && !eventObj.IsUndoRedo )
    {
        var oContextNode = eventObj.Context;
        var oLastChangedNode = 
            XDocument.DOM.selectSingleNode("my:lastChanged");
       
        oLastChangedNode.text = oContextNode.nodeName;
    }
}