Reputation: 2028
I have a WinForms application with an OpenFileDialog in it and I'd like to enable selection of multiple files when the user interacts with the dialog. How can I accomplish this?
Upvotes: 2
Views: 7076
Reputation: 21
C# code
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.MultiSelect = true; //sets to multiple selects
ofd.ShowDialog();
}
Upvotes: 2
Reputation: 20044
Don't know what you did, but when I click File/Open in Visual Studio 2008, it is possible to multi-select all files or just a part of them by clicking on the first file in the list, holding the shift key and then clicking on the last file.
EDIT: ok, you edited the question, seems that I misunderstood you in the first place. Idan K's answer should be correct.
Upvotes: 2
Reputation: 19790
adding the style OFN_ALLOWMULTISELECT will add this see this
If you want to select a folder you should use something else :)
If you are using c++ .net (you didn't state that). You can use the MultiSelect property MSDN
Upvotes: 2
Reputation: 20881
See the OpenFileDialog::Multiselect property, from the docs:
Gets or sets a value indicating whether the dialog box allows multiple files to be selected.
To get the list of files selected you should use the OpenFileDialog::FileNames property.
Upvotes: 4