1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Please Help: Populate Combo box from text file

Discussion in 'C#' started by samweb$, Aug 29, 2010.

  1. samweb$

    samweb$ New Member

    Joined:
    Aug 29, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi All,

    I have just started learning C# and would like to populate a combo box with the list of games defined in gameslist.txt file.

    below is the format of gameslist.txt file
    [category 1]
    game 1
    game 2
    game 3
    game 4

    [category 2]
    game 5
    game 6
    game 7

    [catergory 3]
    game 8
    game 9
    In my GUI Application, I have 2 combo boxes, first combo box will have the category list like [category 1 / category2/ category 3...] and now in the second combo box i should populate only list of games for the particular category selected from the first combo box like [ game1/game2/game3.....].


    Plese help... Thanks in advance.
     
  2. Ami Desai

    Ami Desai Member

    Joined:
    Jan 5, 2017
    Messages:
    42
    Likes Received:
    17
    Trophy Points:
    8
    Location:
    Ahmedabad
    Home Page:
    Hi,

    You can check this
    Code:
    private void Form1_Load(object sender, EventArgs e)
            {
                using (StreamReader reader = new StreamReader(@"d:\test.txt"))
                {
                    string data = "";
                    data = reader.ReadLine();
                    comboBox1.Items.Add(data);
                    data = reader.ReadLine();
                    comboBox1.Items.Add(data);
                    data = reader.ReadLine();
                    comboBox1.Items.Add(data);
                    reader.Close();
                }
            }
    Thanks
     
    shabbir likes this.

Share This Page