Use Listbox to change View

S

Seth U.

Is there a way to force a Listbox to Change to a different View in Infopath
2003? Under the Rules section, I do not see changing the View as an option.

Right now the Form is implemented as selecting a choice in a listbox and
then clicking a Button to change the View. I would like to change the View as
soon as the Selection is made in the listbox and not need to use the button
at all.

Thank you for any advice.
 
Z

Zhang Haiguang

Hi,

Please add a xml file data source as following:
<?xml version="1.0"?>
<views>
<view>View 1</view>
<view>View 2</view>
</views>
Change the content of the element "view" with the names of all your views.
And set it as the data source a list box, add a button, and add the
following codes:
function CTRL2_5::OnClick(eventObj)
{
XDocument.View.SwitchView(
XDocument.DOM.selectSingleNode("/my:myFields/my:field1").text );
}
There is a demo form template on http://www.infojetsoft.com/forms/.

InfoJet Service
InfoPath Web Form
[http://www.infojetsoft.com]
 
Z

Zhang Haiguang

Here is the second step planned, :)
Please add the following codes to the form:
function XDocument::OnLoad(eventObj)
{
var viewsDOM = XDocument.DataObjects[ "Views" ].DOM;
var viewElements = viewsDOM.documentElement.selectNodes( "view" );
for (i=0; i < viewElements.length; i++)
{
viewsDOM.documentElement.removeChild( viewElements[ i ] );
}
for (i=0; i < XDocument.ViewInfos.Count; i++)
{
var viewElement = viewsDOM.createElement( "view" );
viewElement.text = XDocument.ViewInfos[ i ].Name;
viewsDOM.documentElement.appendChild( viewElement );
}
}

The demo form template is updated, http://www.infojetsoft.com/forms/.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top