Switch Views During the OnLoad Event - Greg Collins

InfoPath Dev

This Blog


Greg Collins

Switch Views During the OnLoad Event

InfoPath provides the SwitchView method to allow you to programmatically switch views from within your code. But SwitchView is a method of the View object, which does not exist until after the OnLoad event has completed. Any attempt, therefore, to use the SwitchView method in the OnLoad event handler will fail.

The appropriate method to switch views during the OnLoad event is to set the default view. The default view is the view that will be displayed when the form first loads. Add the following code to the OnLoad event handler to set the default view:

XDocument.ViewInfos("My View Name").IsDefault = true;

thisXDocument.ViewInfos["My View Name"].IsDefault = true;

This code only works in the OnLoad event handler. Attempts to set the default view elsewhere will not accomplish anything—not even result in a failure.

An alternative to setting the default view in the OnLoad event handler is to switch views using the open rules. This performs the same function, yet requires no code.

©2005 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

Published Jun 27 2005, 03:16 PM by Greg Collins
Filed under: , ,


No Comments
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.