Open new form with a different view - InfoPath Dev
in

InfoPath Dev

Open new form with a different view

Last post 06-16-2010 11:49 AM by Jimmy. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 04-09-2010 03:42 PM

    • Lawson
    • Top 100 Contributor
    • Joined on 12-24-2009
    • Virginia
    • Posts 91

    Open new form with a different view

    I have an IP 2003 form with C# code. I would like to add a button that will open up a new form in a different view. Does anybody know how to do this?

  • 04-09-2010 06:32 PM In reply to

    • Lawson
    • Top 100 Contributor
    • Joined on 12-24-2009
    • Virginia
    • Posts 91

    Re: Open new form with a different view

    I am using the following code:

    XDocument NewForm = thisApplication.XDocuments.NewFromSolution(@"C:\Users\Lawson\Desktop\Switch View.xsn");

    thisXDocument.View.SwitchView("View 2");

     

    This code opens a new form, but it doesn't change the view in the new form.

    Does anybody have any suggestions?

  • 04-10-2010 06:26 AM In reply to

    Re: Open new form with a different view

     What happens if you use

     NewForm.View.SwitchView("View 2");

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 04-11-2010 08:09 AM In reply to

    • Lawson
    • Top 100 Contributor
    • Joined on 12-24-2009
    • Virginia
    • Posts 91

    Re: Open new form with a different view

     I get an error message.

     NewForm method does not exist.

  • 06-16-2010 11:04 AM In reply to

    • arcad
    • Not Ranked
    • Joined on 05-10-2010
    • Posts 15

    Re: Open new form with a different view

    Did you find any solutions about this problem?

  • 06-16-2010 11:49 AM In reply to

    Re: Open new form with a different view

    I'm not quite sure why you're getting that error, but I did try this and it doesn't work, because the new form's view can't be changed until the event handler finishes executing.

    One thing you can do is the following:

    1. Create a new field in your template called StartingView
    2. Add a Form Open rule that will switch the view to a certain view when StartingView has a certain value
    3. Create a new form from your template with most of the values as their initial values, except set the StartingView field to the special value you selected for step 2.  Save this XML file somewhere InfoPath will be able to access it.
    4. Change your code so that it uses the NewFromSolutionWithData, and specify the path to the file saved in step 3 as the first argument.  This way, when the new forms are created, they will be loaded with the contents of this XML file as their starting data.

    That should do the trick.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.