Share via


Working with views

When working with a Microsoft Office InfoPath 2003 form, you can write scripting code to access the form's views, and then perform a variety of actions on the data that the views contain. The InfoPath object model supports access to a form's views through the use of the View object.

Overview of the View object

The View object provides the following methods and properties that form developers can use to interact with an InfoPath view.

Name Description
DisableAutoUpdate method Disables synchronization of the XML Document Object Model (DOM) and the view
EnableAutoUpdate method Enables synchronization of the XML DOM and the view
ExecuteAction method Executes an InfoPath editing action
Export method Exports the view as a file of the specified format
ForceUpdate method Synchronizes the XML DOM and the view
GetContextNodes method Returns a reference to the XMLNodes collection, based on the specified XML node and view context or on the current selection in the view
GetSelectedNodes method Returns a reference to the XMLNodes collection, based on the current selection in the view
SelectNodes method Selects a range of XML nodes in the view
SelectText method Selects the text contained in the specified XML node in the view
SwitchView method Switches an InfoPath form to the specified view
Name property Returns a string value indicating the name of the current view
Window property Returns a reference to the Window object associated with the view

Using the View object

The View object is accessed through the View property of the XDocument object. For example, the following code sample demonstrates how to use the Alert method of the UI object to display a message box with the name of the current view that is associated with a form's underlying XML document:

XDocument.UI.Alert("Current view name: " + XDocument.View.Name);

All InfoPath forms contain at least one default view; however, InfoPath also supports the creation of multiple views of a form's underlying XML document. When you have multiple views in a form, the View object can be used to work with the view that is currently active. You can programmatically change the view that is currently active by using the SwitchView method of the View object, as the following code sample demonstrates:

XDocument.View.SwitchView("MySecondView");

Note  The InfoPath object model also provides the ViewInfos collection, which can be used to get information about all of the views implemented in a form.