Try placing the code into the OnContextChange event handler.
This was the only way I could get it to work with this example:
Fully Editable Drop-down List Box
http://www.infopathdev.com/downloads/free/default.aspx?i=0672a57e920b4771b62b1c2
2d5bd314d

Signature
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com
I currently have a textbox that is hidden unless "Other" is selected from a
listbox. This functionality is implemented in Conditional Formatting.
I want to set focus to this textbox. SelectText doesn't work b/c the code
runs before the rules, therefore SelectText fails b/c the textbox isn't
user-selectable.
Ideas?
chloraphil - 05 Aug 2005 14:41 GMT
Here's my code, which is a bit of a hack, but works: (my apologies if it's
not very readable - it reads well in my VS IDE
public void OnContextChange(DocContextChangeEvent e)
{
if (e.Type == "ContextNode")
{
if (e.Context.nodeName.ToString().Equals("my:CI") && //correct context?
(thisXDocument.DOM.selectSingleNode("my:CI/my:Notifications").text.Equals("Other")) && // and "Other" is selected
((thisXDocument.DOM.selectSingleNode("my:CI/my:other").text.Equals("Enter
Notification Type...")) || // and no changes have been made
(thisXDocument.DOM.selectSingleNode("my:CI/my:other").text.Equals(""))))// or
the user just deleted "Enter Notification Type"
{ //then set focus to the 'other' textbo
thisXDocument.View.SelectText(thisXDocument.DOM.selectSingleNode("my:CI/my:other"),Type.Missing);
}
return;
}
}