Export (0) Print
Expand All

ViewObject interface

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)

[GuidAttribute("096cd55d-0786-11d1-95fa-0080c78ee3bb")]
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:


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();
Show:
© 2014 Microsoft