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]); } } }
Comment