Convert a list to buttons.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jj1993
    New Member
    • May 2012
    • 1

    Convert a list to buttons.

    I have a txt file of drinks, and I want to meak a list of buttons of it (the txt file is build like this: fanta : 2 ), how can I make buttons of all the drinks ( I get the first one in a button , but not the others).

    Code:
    Dictionary<string, double> drank = new Dictionary<string, double>();
         string[] words = new string[8];
         Button button;
         <Button> BtnList = new List<Button>();
         double prijs, totaal, waarde;
    
                    using (StreamReader sr = new   StreamReader(@"C:\Users\Jeroen\Desktop\Dranken.txt"))
                    {
    
                        String line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            words = line.Split(':');
                            if (words.Length == 2)
                            {
    
                                string dranken = words[0].Trim();
                                string prijzen = words[1].Trim();
                                prijs = Convert.ToDouble(prijzen);                          
                                drank.Add(dranken, prijs);
                                //MessageBox.Show(Convert.ToString(drank.Count)); (if I use this, I get messageBoxes for each drink)
                                button = new Button();
                                button.Text = dranken;
                                BtnList.Add(button);
                                                          
                            }
                           
                        }
                        for (int i = 0; i < words.Count(); i++)
                        {
                            panelToevoegen.Controls.Add(BtnList[i]);
                        }
                    
                        
                    }
                  
                
            }
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    Why would you loop trough your words instead of your BtnList on Line 29? And where do you place your new buttons? Are you sure their not stacked on top of each other because you don't specify their position? Just some thoughts ;-)

    Comment

    Working...