View Class (Microsoft.Office.InfoPath)
Assembly: Microsoft.Office.InfoPath (in microsoft.office.infopath.dll)
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.
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.
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);
To change the currently active view, use the SwitchView method of the ViewInfoCollection class as shown in the following example.
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.