Populate Drop Down Box - InfoPath Dev
in

InfoPath Dev

Populate Drop Down Box

Last post 03-16-2010 06:52 AM by newbie999. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 03-10-2010 10:22 AM

    Populate Drop Down Box

    I would like to populate a drop down box with employee names. I have written C# code to get the list of names (a ReadOnlyCollection) but I don't know how to add the names to the drop down box. I have tried XPathNavigator and XPathIterator, but the XML shows only the item that the user selected.  I manually added a bunch of items but the items are not seen in the XML. 

    I have read up on this at some length and everything points to creating xml files, which would be difficult with such a large number of items.  I have the information I need in a ReadOnlyCollection and I just want to get it into the drop down box.

     Thanks.

  • 03-10-2010 10:57 AM In reply to

     You will need to have the dropdown populated from a repeating field somewhere (most likely a secondary data source), and you will need to add and remove nodes to that location, not the location where the control is bound.  Aside from the obvious ones (like SelectSingleNode()), these methods should be enough to accomplish what you need:

    XPathNavigator.AppendChild() (no arguments)

    XPathNavidator.DeleteSelf()

    XmlWriter.WriteElementString(string, string, string)

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 03-11-2010 11:11 AM In reply to

    Thanks for the quick reply.  

    I found this page, which seems to suggest the same solution that you have outlined: 

    http://www.bizsupportonline.net/infopath2007/programmatically-fill-populate-drop-down-list-box-infopath-2007.htm  Link #1

    I got this to work, but if players.xml was changed, the drop down list didn't reflect it.  I had to save the file as players2.xml and then set player2.xml as my secondary data source.  Also, I don't understand why he has 2 xml files.  That is, assuming that is was "players" is, and I'm not completely off base.

    Also, you mention XmlWriter.WriteElementString(string, string, string).  Are you saying to programatically create  the XML file to be used as my secondary data source?  That is, loop through my collection and write values to an XML file (using  XmlWriter.WriteElementString(string, string, string)) and save it to a file called (for example) C:\List.xml.  I may have oversimplified things, but I did it a little differently as described here:

    http://msdn.microsoft.com/en-us/library/aex0e7zs.aspx   Link #2

    This seemed to work.  I created an xml file with a list from my TFS lookup, as mentioned in Link #2 and set that as my secondary data source.  When I ran the form, the drop down was populated with the list that was returned from the TFS lookup.   However, if I change the script wherein I change the data in the xml file, the drop down does not reflect that.  That is, even though the xml file generated had indeed changed, (I verified that it indeed had), the drop down contained the data from the old xml file.  I had to rename the file and add the new file as my secondary data source.  This was my experience with the example in Link #1.  For my purposes, the xml file that is used to populate the drop down box would need to be created anew.  Each time the form was loaded, I am creating a new xml file but the drop down doesn't pick up the new file, even though it is the secondary data source.  It seems that once you set a file to be your secondary data source, it takes a snapshot of that file at the time the source was added as a secondary data source and if you change the file, you must rename and add it as your secondary source.

    Also, I am not sure how to use the XPathNavigator.AppendChild() (no arguments) and XPathNavidator.DeleteSelf() methods figure into this.  Would they alleviate the problem I am having with the drop down not reflecting the xml file. 

     

     

     

     

  • 03-16-2010 06:52 AM In reply to

    I did find this link, that refreshes data from secondary source:

    http://office.microsoft.com/en-us/infopath/HP011095581033.aspx

    This has brought me closer to my goal, but there is still a problem (outside the fact that the user has to hit Refresh).  I changed the XML file and hit refresh, but the drop down did not change.  I closed out of the debugger and fired it up again and *that* is when I saw the changes to the drop down list. 

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.