How to select multiple files with an OpenFileDialog?
I have a WinForms application with an OpenFileDialog in it and开发者_如何学Python I'd like to enable selection of multiple files when the user interacts with the dialog. How can I accomplish this?
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.
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
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.
C# code
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.MultiSelect = true; //sets to multiple selects
ofd.ShowDialog();
}
精彩评论