How do you populate a infopath listbox using C# code

D

Deena

I have a infopath listbox control on my infopath form and I would like
to populate it from a SQL database using C# code. I want to have more
control over how it is poplulated. I am too limited when I tell the
control to connect in the control properties. I would like to do this
using C# code instead.
 
G

Greg Collins [InfoPath MVP]

Set the list box to popualte from a repeating group in the main or a secondary DOM. Then in your code, just add/remove rows to the repeating group to affect the options that show in the list.
 
D

Deena

Greg said:
Set the list box to popualte from a repeating group in the main or a secondary DOM. Then in your code, just add/remove rows to the repeating group to affect the options that show in the list.

I appreciate the help that you gave me but I guess I am just a little
too new to InfoPath. I am working out of a infoPath project in Visual
Studio .NET 2005. I guess I need more specifics to understand how to
do this exactly "Set the list box to popualte from a repeating group in
the main or a secondary DOM. Then in your code, just add/remove rows to
the repeating group to affect the options that show in the list." in C#
in the visual studio .NET environment. I have tried looking at
InfoPathDev.com but most of the samples seem to be working directly out
of InfoPath without the visual studio or the code was in Java script.
Can you help me more with this? I am very new to a lot of this. I
have Visual Studio .NET C++ background but I have never worked with C#
or InfoPath before this project.
 
S

S.Y.M. Wong-A-Ton

You can add items to a list by entering them staticly or by binding your list
to a data source. The latter can be either located in your Main DOM or in a
secondary DOM. To bind your list to a data source, the nodes in the data
source have to be repeating. This is what Greg meant with a "repeating group".

The advantage of using a repeating group in the Main DOM of your form
instead of in a secondary data source, is that if you add items to the
repeating group, they will be persisted with the form's data, that is, when
you open the form afterwards you will still have the items you added, whereas
if you add items to a repeating group of a secondary data source (and not to
the source of the secondary data source itself), the items you added will not
be available the next time you open the form.

Adding items to a repeating group is a matter of retrieving the main group
node of the repeating group in code, copying a node from the group using
"cloneNode", changing the values for the new node, and then using
"appendChild" to add the new node to the main group node. Search this
newsgroup on "cloneNode" and "appendChild" to see how this can be done.
 

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