how to add items to a drop-down listbox in Infopath thru coding?

L

lisa

I want to add the elements of one field (ex Field1, whose data is A, B, C.)
to the dropDown listboxcontrol Field2, on hte after change event of Field1
thru coding.
The list items should contain all the words separated by comma from the
content of Field1.
 
G

Greg Collins [InfoPath MVP]

To make this work, your drop-down list cannot have hardcoded values. It pull its values from a repeating list in the main or a secondary data source.

In your OnAfterChange event handler, you would walk through your delimited list and insert new nodes into the repeating group. Then your drop-down list will automatically update with the values.
 
L

lisa

Greg,
Thanks for your response.

But I wanted to add items to the listbox.
the Listbox1.Items.Add() or Listbox1.AddItem("Item") does not work.
Could you please tell me what coding I need to put under the OnAfterchange
event code in MSE so that I can add items of my own programmatically.

Thanks
Lisa
 
G

Greg Collins [InfoPath MVP]

Right - exactly. You cannot directly add items to a hardcoded list in a ListBox control. Your control needs to be populated dynamically from a repeating group (main DOM or secondary DOM). Your OnAfterChange event handler would add nodes to the repeating group. The control will automatically update with the current list in the repeating group.

There is no way to directly alter the hardcoded set of list values -- you must use a dynamic technique as I describe above.

Good luck!
 

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