ViewObject interface

Office 2013 and later

Represents a view within a Microsoft InfoPath form.

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

public interface ViewObject : View

This type is a wrapper for a coclass that is required by managed code for COM interoperability. Use this type to access the members of the COM interface implemented by this coclass. For information about the COM interface, including a link to descriptions of its members, seeView.

The ViewObject object provides a number of properties and methods that can be used to programmatically interact with an InfoPath view, including methods for selecting data contained in the view, switching from one view to another, synchronizing the view with a form's underlying XML document, and executing an InfoPath editing action

In the following example, the IsDefault property of the ViewInfoObject object is used to determine whether a view is the default view of the form. Then the code uses the Name property of the ViewInfo object to display the name of the default view in a message box.

ViewInfos viewInfos;
// Set a reference to the ViewInfos collection.
viewInfos = thisXDocument.ViewInfos;
// Determine the default view and display a 
// message box with its name.
foreach (ViewInfo viewInfo in viewInfos)
 if (viewInfo.IsDefault)
  thisXDocument.UI.Alert("The default view is: " + viewInfo.Name);

The View object is accessed through the View property of the XDocument object. For example, the following code sets a reference to a form's currently active view:

View view;

view = thisXDocument.View;

To change the currently active view, you can use the SwitchView method of the View object as follows:


To force an update of a view based on changes in a form's underlying XML document, you can use the ForceUpdate method of the View object, as shown here: