Answers for "add items to listbox from text file c#"

C#
2

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();
Posted by: Guest on November-26-2020
0

add text file to listbox c#

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);

            }
        }
    }
Posted by: Guest on November-07-2020

Code answers related to "add items to listbox from text file c#"

C# Answers by Framework

Browse Popular Code Answers by Language