I have a small piece of code that gets called form my custom task pane. This
code is supposed to change the current view and then select a certain node
within the form. I have two buttons, (button1)one just switches the view and
(button2)the other switches the view and selects a node. If i click button2,
then it will switch the view but then fail when SelectNodes is called.
Strangely, if i click button1 and then button2 then button2 works as
expected. Is there some problem with switching views and selecting a node in
the same function? I have attached the code i use for slecting a node below.
Thanks for your help.
-Greg G
IXMLDOMNode tmpNode = thisXDocument.DOM.selectSingleNode( "//"+nodeName);
thisXDocument.View.SelectNodes(tmpNode,Type.Missing,Type.Missing);
If I understand you correctly, you have 2 views.
Both View 1 and View 2 contain Button1 and Button2.
View 1:
Button 1 switches to View 2.
Button 2 switches to View 2 and selects a field
View 2:
Button 1 switches to View 1.
Button 2 selects a field in View 2.
I believe the problem with View1/Button2 is a timing issue. While the view has not yet been built, the code is attempting to select a field (which doesn't yet exist). I ran into a similar issue in my InfoPathDev.com Example, "Fully Editable Drop-Down List Box".
The reason View2/Button2 works (as described above) is because the field exists when the attempt is made to select it.
In order to get View1/Button2 to work, you can try setting a flag, and then in the OnSwitchView event handler, verify you are in View2, check for the flag, and then select the field. I believe at this point the view is completely built and the field will be selected without an error.
Let me know the results when you've tried this.

Signature
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com
I have a small piece of code that gets called form my custom task pane. This
code is supposed to change the current view and then select a certain node
within the form. I have two buttons, (button1)one just switches the view and
(button2)the other switches the view and selects a node. If i click button2,
then it will switch the view but then fail when SelectNodes is called.
Strangely, if i click button1 and then button2 then button2 works as
expected. Is there some problem with switching views and selecting a node in
the same function? I have attached the code i use for slecting a node below.
Thanks for your help.
-Greg G
IXMLDOMNode tmpNode = thisXDocument.DOM.selectSingleNode( "//"+nodeName);
thisXDocument.View.SelectNodes(tmpNode,Type.Missing,Type.Missing);