Managed code, drop-down-list

J

Jim

Can anyone provide me a snippet of code where an item in a drop-down-list is
selected, probably via the onload event. For example, there is a drop-down of
the fifty states amd it's bound to a web service or sql query. How do have,
let's say Texas, selected on the drop-down when the infopath form loads.

Thanks in advance,
Jim
 
F

Franck Dauché

Hi Jim,

If you are storing IDs and displaying Names with your drop-down (let's say
Texas is 47), then what you have to do is to select your node in the schema
and set its value to 47.

Does it make sense?

Regards,

Franck Dauché
 
J

Jim

It does make sense, thanks. If you have a snippet handy, I'd appreciate it.

Thanks again,
Jim
 
F

Franck Dauché

Sure. Put the following C# code in the OnLoad:

IXMLDOMNode oField =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:fieldLinkedToDropDown");
//replace by your own XPath
oField.text = "47";

Regards,

Franck Dauché
 
J

Jim

Oh, the same way one would handle populating like a textbox! I'm sorry, I
already knew how to do that. Thanks a bunch Frank!
 

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