C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-11-2005, 01:32 PM   #1
Registered User
 
Join Date: Aug 2005
Posts: 16
reading in files and populating the Combobox1 dropdown?

I was curios if anyone knows how i could use StreamReader.ReadLine on a Text file and save each instance to an "dimensioned array" even to display it to the screen....
in a nut shell i would like to say read a file like:
("example.txt")
the array portion of this would be on the c# side of the file. the names or the right side of the = is the text file fields so to say.

array1 =Texas
array2 =Florida
array3 =Southeast

then, i would like to add those arrays to another variable like:

OneArray<0>=array1
OneArray<1>=array2
OneArray<2>=array3

this should be easy enough but, im just starting out coding here. i have looked on msdn for collections, arraylist, and a few other commands but, nothing seems to be able to handle this....
eventually i would like to use this data in a combobox for end users to choose from. if this is possible then great! if not well then thanks for looking at it anyways. i have not found any code that would let me create this type of structure. I usually code in "pick" haha but, im sure if such a simple text based language can do it that c++ or c# should have some mannerism for this case.

Last edited by fingerlickin; 08-11-2005 at 01:58 PM.
fingerlickin is offline   Reply With Quote
Old 08-12-2005, 07:11 AM   #2
the hat of redundancy hat
 
nvoigt's Avatar
 
Join Date: Aug 2001
Location: Hannover, Germany
Posts: 2,769
You can read lines from a file by using a stream reader as you already mentioned.

You can split a line at a specific point by using the string.Split function.

If you split your line at the = symbol you have a pair of words, a key ( array1 ) and a value ( Texas ).

You can save a key/value pair with any IDictionary class. A Hashtable comes to mind here.

You can later access the hashtable and get a value for the key you are looking for by using the index operator []:
value = myhashtable["key"];

This would be a rather complex way of doing things. If you need values, you can add them by code or IDE. If you need them dynamic and from a file, just read the lines and add each line to the combobox.
__________________
hth
-nv

She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

When in doubt, read the FAQ.
Then ask a smart question.
nvoigt is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump


All times are GMT -6. The time now is 05:21 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22