in

InfoPath Dev

This Blog

Syndication

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:

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

C#:
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: , ,

Comments

No Comments

About Greg Collins

I am a Microsoft MVP.

I developed many of the Microsoft sample solutions that shipped with InfoPath v1 and currently develop InfoPath solutions for a living, exploiting my strong background in programming, Web development and graphic design.

I developed the original InfoPathDev Web site and numerous other Web sites. I enjoy spending time with my family, the outdoors, digital photography, graphic design and desktop publishing.

Check out my web site at http://www.braintrove.com
Copyright © 2003-2007 Qdabra Software. All rights reserved.
View our Terms of Use.