none
selecting multiple CSV files and displaying them in a listbox RRS feed

  • Question

  • Hi,

    How can i select multiple files in openfiledialog and list them in a listbox?


    Akshay

    Thursday, May 2, 2019 4:28 AM

Answers

  • Hi anonymous_3210,

    To achieve multiple selecting, you need to set "Multiselect" to "true". And here is a demo you can refer to:

        private void btSelect_Click(object sender, EventArgs e)
        {
            OpenFileDialog openfiledialog1 = new OpenFileDialog();
            openfiledialog1.Multiselect = true;
            openfiledialog1.InitialDirectory = "d:\\cvs\\";
            if (openfiledialog1.ShowDialog() == DialogResult.OK)
            {
                for (int fi = 0; fi < openfiledialog1.FileNames.Length; fi++)
                {
                    listBox1.Items.Add(openfiledialog1.FileNames[fi].ToString());
                }
            }
        }

    Result:

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 2, 2019 6:19 AM

All replies


  • How can i select multiple files in openfiledialog and list them in a listbox?

    Again?

    How does this differ from your numerous other threads on reading a CSV file?

    - Wayne

    Thursday, May 2, 2019 4:35 AM
  • Hi anonymous_3210,

    To achieve multiple selecting, you need to set "Multiselect" to "true". And here is a demo you can refer to:

        private void btSelect_Click(object sender, EventArgs e)
        {
            OpenFileDialog openfiledialog1 = new OpenFileDialog();
            openfiledialog1.Multiselect = true;
            openfiledialog1.InitialDirectory = "d:\\cvs\\";
            if (openfiledialog1.ShowDialog() == DialogResult.OK)
            {
                for (int fi = 0; fi < openfiledialog1.FileNames.Length; fi++)
                {
                    listBox1.Items.Add(openfiledialog1.FileNames[fi].ToString());
                }
            }
        }

    Result:

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 2, 2019 6:19 AM