user1606185
0
Q:

add items to listbox from text file c#

ListBox lb = new ListBox();
            System.IO.StreamReader sr = new System.IO.StreamReader("userTypes.txt");

            while (!sr.EndOfStream)
            {
                lb.Items.Add(sr.ReadLine());
            }
            sr.Close();
1
 OpenFileDialog f = new OpenFileDialog();
    if (f.ShowDialog() ==DialogResult.OK)
    {
        listBox1.Items.Clear();

        List<string> lines = new List<string>();
        using (StreamReader r = new StreamReader(f.OpenFile()))
        {
            string line;
            while ((line = r.ReadLine()) != null)
            {
                listBox1.Items.Add(line);

            }
        }
    }
0

New to Communities?

Join the community