Your steps do not account for what you are wanting to do... namely set a default value in the OnLoad code.
If you do not FORCE a default view, then yes, InfoPath will preview using the CURRENT view. This is the expected behavior.
It sounds like you are wanting to always force Vew 1 to show up first. Let's modify your steps a bit... I tested this before replying to you last time...
1. Start IP
2. "Design a form"
3. "New blank form"
4. You're looking at "View 1". Type "View 1" onto it.
5. "Views"; "Add a new view". Name "View 2"
6. You're looking at "View 2". Type "View 2" onto it.
7. Choose Programming | On Load Event from the Tools menu.
8. In the OnLoad event handler, type 'XDocument.ViewInfos("View 1").IsDefault = true;'
9. Save your form code and close the script editor.
10. Select "Preview Form" (either from toolbar, or from "File" menu);
--
Greg Collins [InfoPath MVP]
Please visit:
http://www.InfoPathDev.com
[Posted to InfoPathDev.com too.]
Please be kind enough to try something very simple for me. I feel I'm going
mad! I've now tested from scratch on another PC here, and I do *not* find
that Default View is taken into account from design mode!
Very simple steps:
1. Start IP
2. "Design a form"
3. "New blank form"
4. You're looking at "View 1". Type "View 1" onto it.
5. "Views"; "Add a new view". Name "View 2"
6. You're looking at "View 2". Type "View 2" onto it.
7. Select "Preview Form" (either from toolbar, or from "File" menu)
What do you see? I see "View 2"! You can see from "Views" pane that "View
1" is default. You can swap which is default as much as you like; but I
always get whichever one I am looking at in design mode up first. Don't you?
Same on another PC.
If you then save the file, I find the same whenever I reopen the file for
design. If I open it for fill out, the default view *does* come up.
I'd like this sorted before I tackle the "real" problem, which seems to be
worse...
:
Hmmmm.... So now I technically have two problems (at least on my machine)
then:
1. Default View is *not* taken into account for me from design mode (as per
repro steps below on brand new IP form, two views, no code, nothing...)
2. On real form, reagrdless design/open mode, Default View *always* ignored
and set to one particular view.
Inexplicable? Related? Why do I begin to feel a "uninstall & reinstall IP"
coming on? ...
I'm happy continuing this conversation here or at InfoPathDev.com. Probably
prefer the latter. Except that it's down (again)...
:
To answer your first question... the default view *IS* taken into account during preview from the designer.
--
Greg Collins [InfoPath MVP]
Please visit:
http://www.InfoPathDev.com
OK, I'm starting to look into this.
Can I *please* have an answer first off to a very simple question: is
"Default View" taken into account when previewing from *design* mode?
In a test, I create a blank form and an extra view, i.e. "View 1" & "View
2". I set "View 2" as the default. I save.
Now, I find:
* if I "Open" form to fill out, "View 2" comes up
* if I "Design" form and preview, then whatever view I am looking at in
design mode comes up
I have tried every combination of getting into Open/Design mode (from IP,
from Explorer, etc. etc.) and this is always the behaviour. Open mode
respects my default, from design mode does not.
Is this or is this not expected behaviour?
(Having said this, this still doesn't solve my original problem: in that
form, it still doesn't matter what I'm viewing in design mode, or when I
open, it *always* comes up one one (non-default) viw. But let's wait on that
till I get an answer to this part...)
:
I'm stumped on this one...
Developing a form. It had one view. I introduce a second view, and set that
as default view. Works fine when accessed from any machine. Except... On my
machine (where I develop), the original view gets shown first. Believe me, I
have tried everything: resetting, resaving, rebooting, starting from either
"open" or "design" mode ... If I place a debugger statement in MS Script
OnLoad() event and run on my machine, I can see it says the *original* view
is the default, so no wonder. But where's it getting that from: I can see
quite clearly that I have set the new view as default? The only thing I can
think of is a cached copy/saved setting somewhere/somehow?
I have checked I do not have any load rules, user views etc. For now, I have
created a rule in "Form Options" for "Open behaviour" telling it to switch to
the other view, and that gets my by, but what the heck?...