<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>File Programs &#187; Control Data</title>
	<atom:link href="http://fileprograms.com/tag/control-data/feed/" rel="self" type="application/rss+xml" />
	<link>http://fileprograms.com</link>
	<description></description>
	<lastBuildDate>Thu, 09 Feb 2012 05:38:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How do I populate a ComboBox in vb.net (visual studio 2008) with .txt file?</title>
		<link>http://fileprograms.com/how-do-i-populate-a-combobox-in-vb-net-visual-studio-2008-with-txt-file/</link>
		<comments>http://fileprograms.com/how-do-i-populate-a-combobox-in-vb-net-visual-studio-2008-with-txt-file/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 07:20:29 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Vb.net File]]></category>
		<category><![CDATA[.csv]]></category>
		<category><![CDATA[.txt]]></category>
		<category><![CDATA[2008]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[Bound]]></category>
		<category><![CDATA[Carriage Return]]></category>
		<category><![CDATA[ComboBox]]></category>
		<category><![CDATA[Combobox Vb]]></category>
		<category><![CDATA[Comma Comma]]></category>
		<category><![CDATA[Comma Delimited]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[Control Data]]></category>
		<category><![CDATA[Core Approach]]></category>
		<category><![CDATA[Data Control]]></category>
		<category><![CDATA[Elements]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[Hello]]></category>
		<category><![CDATA[Main Goal]]></category>
		<category><![CDATA[Memory]]></category>
		<category><![CDATA[Ms Excel]]></category>
		<category><![CDATA[Namespace]]></category>
		<category><![CDATA[populate]]></category>
		<category><![CDATA[Semicolon]]></category>
		<category><![CDATA[String Object]]></category>
		<category><![CDATA[Studio]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[Visual]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://fileprograms.com/how-do-i-populate-a-combobox-in-vb-net-visual-studio-2008-with-txt-file/</guid>
		<description><![CDATA[Question by WisoBe: How do I populate a ComboBox in vb.net (visual studio 2008) with .txt file? Hello, I would like to populate a combobox in vb.net with a .txt file. Unfortunately I don&#8217;t know how to do this. The &#8230; <a href="http://fileprograms.com/how-do-i-populate-a-combobox-in-vb-net-visual-studio-2008-with-txt-file/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong><i>Question by WisoBe</i>: How do I populate a ComboBox in vb.net (visual studio 2008) with .txt file?</strong><br />
Hello,</p>
<p>I would like to populate a combobox in vb.net with a .txt file. Unfortunately I don&#8217;t know how to do this. The main goal afterwards is to populate a second and a third combobox based on the previous one. I didn&#8217;t find any solution on Internet. <img src='http://fileprograms.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  Could somebody please help me with this issue ? Thank you.</p>
<p><strong>Best answer:</strong></p>
<p><i>Answer by ross613</i><br/>Interesting problem.  But not a hard one to solve &#8211; if we apply the core approach used to solve any problem with software: divide and conquer.  The problem can be divided as follows:</p>
<p>- standardize your data (the .txt file(s)) by either determining how records are delimited; by a character like a semicolon or comma (comma-delimited data is used by MS Excel and is typically a text file ending with .csv) or maybe it&#8217;s data delimited by a carriage return &#8211; that is one record per line<br />
- determine how the data will be organized in memory; will it be elements of an array or, more likely, some kind of objects that can easily be consumed by the control you&#8217;re using (in this instance, the ComboBox)<br />
- format the presentation of the data; is there anything we need to do to the data when its displayed in the combobox or can we display it as-is?</p>
<p>So the first step is reading the data and you&#8217;ll want to consider using the File object in the System.IO namespace and doing something like a File.Open() to read your text file into a string object.</p>
<p>Next, you&#8217;ll want to break up the string into the individual data records we&#8217;ll use as items to be displayed in the ComboBox: String.Split() is one way of doing this.  However, you may recall that the ComboBox is a special kind of control called a &#8220;data bound control&#8221;; which means it offers properties and methods that specifically facilitate working with data.  In particular, the ComboBox.DataSource property is compatible with objects that expose the IEnumberable interface &#8211; and so it might be worthwhile converting that string array (represented as string()) to a generic List (or List<string>).  Once you have your data in a List<string>, you can simply assign that member to the DataSource property of your ComboBox control and you&#8217;ll see your data displayed (in a raw, untreated form) therein:</p>
<p>Dim rawTextData As string;<br />
&#8230; &#8216; insert logic to read text file into rawTextData here&#8230;</p>
<p>Dim myTextData As string()<br />
myTextData = rawTextData.Split(Chr(10))<br />
&#8216; at this point your text file is records in the string array myTextData<br />
Dim bindableTextData As New List(Of String)</p>
<p>For Each s As string In myTextData<br />
·····bindableTextData.Add(s)<br />
Next</p>
<p>ComboBox.DataSource = bindableTextData</p>
<p>NOTE: The above syntax may not all be entirely correct &#8211; I work mostly in C#, but the ideas are basically the same since it&#8217;s all .NET.  <img src='http://fileprograms.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Good luck!</p>
<p><strong>What do you think? Answer below!</strong></p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Ffileprograms.com%2Fhow-do-i-populate-a-combobox-in-vb-net-visual-studio-2008-with-txt-file%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:80px"></iframe>]]></content:encoded>
			<wfw:commentRss>http://fileprograms.com/how-do-i-populate-a-combobox-in-vb-net-visual-studio-2008-with-txt-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

