Share via


View Class

Represents a view within a form.

Namespace: Microsoft.Office.InfoPath
Assembly: Microsoft.Office.InfoPath (in microsoft.office.infopath.dll)

Syntax

'Declaration
'Usage

Remarks

The View class provides 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.

Note

The InfoPath object model does not provide a collection of View objects, but it does provide the ViewInfoCollection class which provides a collection of ViewInfo objects, each of which provides information about the corresponding view it represents. Additionally, the View class provides the ViewInfo property, which allows you to access information about the associated view.

Example

The View object that represents the current view is accessed using the CurrentView property of the XmlForm class. In the following example, first a View object is created to reference the form's currently active view. Then, the ViewInfo property is used to access the ViewInfo object for the view and display its name in a message box.

// Set a reference to the current view.
View thisView = this.CurrentView;

// Display the view's name.
MessageBox.Show(thisView.ViewInfo.Name);
' Set a reference to the current view.
Dim thisView As View = Me.CurrentView

' Display the view's name.
MessageBox.Show(thisView.ViewInfo.Name)

To change the currently active view, use the SwitchView method of the ViewInfoCollection class as shown in the following example.

this.ViewInfos.SwitchView("View2");
Me.ViewInfos.SwitchView("View2")

To force an update of a view to display information that has been programmatically changed in the form's underlying XML document, you can use the ForceUpdate method of the View class, as shown in the following example.

this.CurrentView.ForceUpdate();
Me.CurrentView.ForceUpdate()

Inheritance Hierarchy

System.Object
  Microsoft.Office.InfoPath.View

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

View Members
Microsoft.Office.InfoPath Namespace