<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Populate a Drop-Down List Box via Code</title><link>https://www.infopathdev.com:443/blogs/greg/archive/2004/07/12/Populate-a-Drop_2D00_Down-List-Box-via-Code.aspx</link><description>NOTE: This article was written for the original InfoPath 2003, which did not support secondary data sources. You can still use code to populate a drop-down list box, but the better approach is to have the drop-down list populate from a secondary data</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Bind DropDown to Views | keyongtech</title><link>https://www.infopathdev.com:443/blogs/greg/archive/2004/07/12/Populate-a-Drop_2D00_Down-List-Box-via-Code.aspx#37490</link><pubDate>Thu, 22 Jan 2009 00:59:17 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:37490</guid><dc:creator>Bind DropDown to Views | keyongtech</dc:creator><description>&lt;p&gt;Pingback from &amp;nbsp;Bind DropDown to Views | keyongtech&lt;/p&gt;
&lt;img src="https://www.infopathdev.com:443/aggbug.aspx?PostID=37490" width="1" height="1"&gt;</description></item><item><title>re: Populate a Drop-Down List Box via Code</title><link>https://www.infopathdev.com:443/blogs/greg/archive/2004/07/12/Populate-a-Drop_2D00_Down-List-Box-via-Code.aspx#25991</link><pubDate>Mon, 28 Jan 2008 21:16:03 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:25991</guid><dc:creator>10basetom</dc:creator><description>&lt;p&gt;On a related note, I noticed that when you populate a drop-down list with a data connection from a SharePoint form library, the first item of the drop-down list is always empty. Is there a way, through code or other means, to make the first item display &amp;quot;Select...&amp;quot;?&lt;/p&gt;
&lt;img src="https://www.infopathdev.com:443/aggbug.aspx?PostID=25991" width="1" height="1"&gt;</description></item><item><title>re: Populate a Drop-Down List Box via Code</title><link>https://www.infopathdev.com:443/blogs/greg/archive/2004/07/12/Populate-a-Drop_2D00_Down-List-Box-via-Code.aspx#25671</link><pubDate>Tue, 15 Jan 2008 17:56:14 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:25671</guid><dc:creator>Greg Collins</dc:creator><description>&lt;p&gt;I added a note to the beginning of this article to identify that this method is no longer recommended. It was written before secondary data sources were available. &lt;/p&gt;
&lt;p&gt;Secondary data sources are the correct approach to filling in drop-down options now.&lt;/p&gt;
&lt;img src="https://www.infopathdev.com:443/aggbug.aspx?PostID=25671" width="1" height="1"&gt;</description></item><item><title>re: Populate a Drop-Down List Box via Code</title><link>https://www.infopathdev.com:443/blogs/greg/archive/2004/07/12/Populate-a-Drop_2D00_Down-List-Box-via-Code.aspx#24763</link><pubDate>Wed, 28 Nov 2007 21:43:37 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:24763</guid><dc:creator>MonkeyCMonkeyDo</dc:creator><description>&lt;p&gt;How would you do this using an ADO.NET connection in the code behind(C#) &amp;nbsp;in InfoPath 2007??&lt;/p&gt;
&lt;p&gt;Is there a way to populate a drop-down list box strictly using code?&lt;/p&gt;
&lt;p&gt;Thank you for your expertise!&lt;/p&gt;
&lt;img src="https://www.infopathdev.com:443/aggbug.aspx?PostID=24763" width="1" height="1"&gt;</description></item><item><title>re: Populate a Drop-Down List Box via Code</title><link>https://www.infopathdev.com:443/blogs/greg/archive/2004/07/12/Populate-a-Drop_2D00_Down-List-Box-via-Code.aspx#22027</link><pubDate>Thu, 26 Jul 2007 21:29:17 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:22027</guid><dc:creator>mlansdaal</dc:creator><description>&lt;p&gt;skrile - If you add a secondary datasource above as sirwally suggested, IP will create a secondary dataconnection called &amp;quot;sections&amp;quot;. In my case, it was called &amp;quot;TARGETS&amp;quot;. &amp;nbsp;You will need to decide where your code is going to run that will manipulate the contents of that data source (e.g., at form load, on context change, etc.).&lt;/p&gt;
&lt;p&gt;//Get the data source and clear out the child nodes&lt;/p&gt;
&lt;p&gt;IXMLDOMDocument targetsDoc = thisXDocument.GetDOM( &amp;quot;Targets&amp;quot; );&lt;/p&gt;
&lt;p&gt;IXMLDOMNode targetsNode = targetsDoc.selectSingleNode( &amp;quot;/TARGETS&amp;quot; );&lt;/p&gt;
&lt;p&gt;targetsNode.childNodes.reset();&lt;/p&gt;
&lt;p&gt;//Create some new child node values and add to the datasource		&lt;/p&gt;
&lt;p&gt;IXMLDOMNode t1Node = targetsDoc.createElement( &amp;quot;TARGET&amp;quot; );&lt;/p&gt;
&lt;p&gt;t1Node.text = &amp;quot;1&amp;quot;;&lt;/p&gt;
&lt;p&gt;IXMLDOMNode t2Node = targetsDoc.createElement( &amp;quot;TARGET&amp;quot; );&lt;/p&gt;
&lt;p&gt;t2Node.text = &amp;quot;2&amp;quot;;&lt;/p&gt;
&lt;p&gt;targetsNode.appendChild( t1Node );&lt;/p&gt;
&lt;p&gt;targetsNode.appendChild( t2Node );&lt;/p&gt;
&lt;p&gt;The above code caused my dropdown list to display choices of &amp;quot;1&amp;quot; and &amp;quot;2&amp;quot;.&lt;/p&gt;
&lt;img src="https://www.infopathdev.com:443/aggbug.aspx?PostID=22027" width="1" height="1"&gt;</description></item><item><title>re: Populate a Drop-Down List Box via Code</title><link>https://www.infopathdev.com:443/blogs/greg/archive/2004/07/12/Populate-a-Drop_2D00_Down-List-Box-via-Code.aspx#21815</link><pubDate>Thu, 19 Jul 2007 19:29:26 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:21815</guid><dc:creator>skrile</dc:creator><description>&lt;p&gt;sirwally...this looks very interesting. &amp;nbsp;However, I'm a bit confused about the &amp;quot;code&amp;quot; that could be written to add/remove/update elements. &amp;nbsp;Do you have an example?&lt;/p&gt;
&lt;img src="https://www.infopathdev.com:443/aggbug.aspx?PostID=21815" width="1" height="1"&gt;</description></item><item><title>re: Populate a Drop-Down List Box via Code</title><link>https://www.infopathdev.com:443/blogs/greg/archive/2004/07/12/Populate-a-Drop_2D00_Down-List-Box-via-Code.aspx#21143</link><pubDate>Fri, 22 Jun 2007 07:42:48 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:21143</guid><dc:creator>sirwally</dc:creator><description>&lt;p&gt;In Step #4 above the repeating element should have been section, not sections. &amp;nbsp;Also, to clarify, in Step #5 the elements you would add/remove/update would be section elements (which I guess was probably obvious :-).&lt;/p&gt;
&lt;img src="https://www.infopathdev.com:443/aggbug.aspx?PostID=21143" width="1" height="1"&gt;</description></item><item><title>re: Populate a Drop-Down List Box via Code</title><link>https://www.infopathdev.com:443/blogs/greg/archive/2004/07/12/Populate-a-Drop_2D00_Down-List-Box-via-Code.aspx#21142</link><pubDate>Fri, 22 Jun 2007 07:37:51 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:21142</guid><dc:creator>sirwally</dc:creator><description>&lt;p&gt;Actually, you can populate a drop-down list via code without using a dreaded preserve code block.&lt;/p&gt;
&lt;p&gt;Say, for example you want a list of sections in your form that will be populated programatically. &amp;nbsp;You can achieve this by doing the following:&lt;/p&gt;
&lt;p&gt;1) Create an XML (sections.xml) file that contains two identical, empty nodes within the root node. &amp;nbsp;i.e.&lt;/p&gt;
&lt;p&gt;&amp;lt;sections&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;&amp;lt;section/&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;&amp;lt;section/&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;/sections&amp;gt;&lt;/p&gt;
&lt;p&gt;2) Import the XML file as a resource file.&lt;/p&gt;
&lt;p&gt;3) Create a data connection to resource file added in Step #2.&lt;/p&gt;
&lt;p&gt;4) Add a drop-down to the form and bind it to the data connection created in Step #3. &amp;nbsp;Select the repeating element -- there should only be one (sections in this example). &amp;nbsp;If InfoPath complains about not finding a repeating element, you didn't complete Step #1 correctly ;-)&lt;/p&gt;
&lt;p&gt;5) Write code that modifies the DOM of the data connection to add/remove/update elements as needed.&lt;/p&gt;
&lt;img src="https://www.infopathdev.com:443/aggbug.aspx?PostID=21142" width="1" height="1"&gt;</description></item></channel></rss>