Jithendrian

Hi

I have an Infopath 2007 Form. The form has 3 views(Default, First, Second). But i need to change the view from default view to First view during the loading of the form. So i tried to change the view by specifying

" ViewInfos.SwitchView("FirstView") " in the InternalStartUp() method in the CodeBehind of the form. But i get an "Object Reference not set to the instance of an object" exception.

But when i try to execute the same on a click of a button the view of the form is changed. But my requirement is to change the view while loading the form. How to do this

TIA

Cheers

Jithendrian. R



Re: SharePoint - InfoPath Forms Services Changing Views in Infopath Form

David Dean

You can set the default view in the Loading event for the form. This event handler can be added using the Tools / Programming menu in InfoPath or the top-level Insert menu if you are using Visual Studio.

Code Snippet

Public Sub FormEvents_Loading(ByVal sender As Object, ByVal e As LoadingEventArgs)

e.SetDefaultView("My View")

End Sub

The LoadingEventArgs also provides an InputParameters property that contains startup parameters for the form.






Re: SharePoint - InfoPath Forms Services Changing Views in Infopath Form

Jithendrian

Hi David,

Thanks for the response. i was able to achieve what u said. But i do have one more query. actually i need to use the infopath form in my windows application. So by using FormControl i am loading the infopath form. The thing is, the view inside the infopath form has to be loaded based on the person using the application. If the user is admin then his corresponding view has to be loaded.

So basically what i did is after loading the infopath form through FormControl i tried to change the view based on the user. The following is the code

private Microsoft.Office.InfoPath.FormControl frmCtrlInfopath;

string fileLocation,viewName;

fileLocation = System.Configuration.ConfigurationManager.AppSettings["FormLocation"];

this.frmCtrlInfopath.NewFromFormTemplate(fileLocation);

viewName = System.Configuration.ConfigurationManager.AppSettings["AdminView"];

this.frmCtrlInfopath.XmlForm.ViewInfos.SwitchView(viewName);

When i try to execute i get a COMException stating "InfoPath cannot execute any view-related object model calls. The view is not ready."

I need help regarding this. A sample code snippet would be helpful

TIA

Cheers

Jithendrian. R





Re: SharePoint - InfoPath Forms Services Changing Views in Infopath Form

Ishai Sagi

Jithendrian,

It would be polite of you to start a new thread with this new question, and mark David's answer as correct. This way David earns points, people know that your question was answered, and your question gets exposed to more people.






Re: SharePoint - InfoPath Forms Services Changing Views in Infopath Form

Jithendrian

Hi Sagi,

Sorry that i was not aware of thet process. as u sai wil start a new thread itself.

Cheers

Jithendrian