FormEvents.ViewSwitched Event (Microsoft.Office.InfoPath)

Occurs after a view of a form has been successfully switched.

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

Syntax

'Declaration
Public Event ViewSwitched As ViewSwitchedEventHandler
'Usage
Dim instance As FormEvents
Dim handler As ViewSwitchedEventHandler

AddHandler instance.ViewSwitched, handler
public abstract event ViewSwitchedEventHandler ViewSwitched

Exceptions

Exception type Condition

InvalidOperationException

The developer attempted to bind the event in some location other than the InternalStartup method.

Remarks

Important

The ViewSwitched event is not meant to be instantiated by the developer in form code. You should only add event handlers for form-level events from the Microsoft Office InfoPath 2007 design mode user interface. When you add an event handler to your form template from the design mode user interface, InfoPath generates code in the InternalStartup method of your form code file using the EventManager class and the member of the FormEvents class to bind the event to its event handler. For information on how to add event handlers in InfoPath design mode, see How to: Add an Event Handler.

The ViewSwitched event is bound using the ViewSwitchedEventHandler delegate.

The ViewSwitched event cannot be cancelled.

Note

The ViewSwitched event also occurs when a form is first opened.

This type or member can be accessed from code running in forms opened in Microsoft Office InfoPath 2007 or in a Web browser.

Example

In the following example, the event handler for the ViewSwitched event is used to show the name of the view displayed when the view change occurs.

public void FormEvents_ViewSwitched(object sender, ViewSwitchedEventArgs e)
{
   MessageBox.Show("Loading the view: " + 
      this.CurrentView.ViewInfo.Name);
}
Public Sub FormEvents_ViewSwitched(sender As Object, _
   e As ViewSwitchedEventArgs)
   MessageBox.Show("Loading the view: " & _
      Me.CurrentView.ViewInfo.Name)
End Sub

See Also

Reference

FormEvents Class
FormEvents Members
Microsoft.Office.InfoPath Namespace