Thread: reading in files and populating the Combobox1 dropdown?

  1. #1
    Registered User
    Join Date
    Aug 2005

    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:
    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:


    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.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    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.

    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.

Popular pages Recent additions subscribe to a feed