Share via


ViewObject interface

Represents a view within a Microsoft Office InfoPath form.

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

Syntax

'Declaration
<GuidAttribute("096CD55D-0786-11D1-95FA-0080C78EE3BB")> _
Public Interface ViewObject _
    Inherits View
'Usage
Dim instance As ViewObject
[GuidAttribute("096CD55D-0786-11D1-95FA-0080C78EE3BB")]
public interface ViewObject : View

Remarks

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

Examples

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:

thisXDocument.View.SwitchView("View2");

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:

thisXDocument.View.ForceUpdate();

See also

Reference

ViewObject members

Microsoft.Office.Interop.InfoPath namespace