I have a OpenFileDialog
and its MultiSelect
property is ON. My question is how can I limit the number of items to be selected, for example 5 items only?
Thanks
I have a OpenFileDialog
and its MultiSelect
property is ON. My question is how can I limit the number of items to be selected, for example 5 items only?
Thanks
You can use the FileOk event to check the file(s) selected by the user when he clicks the OK button. If you are not happy then display a message and set the CancelEventArgs.Cancel property to True to prevent the dialog from closing. Like this:
There is no built-in feature for that in
OpenFileDialog
as far as I can see. Possible solution is to checkFileNames
returned from the dialog. If it count more than 5, for example, alert user and stop without operating the files.You cannot. But you have alternatives:
1.- A good alternative could be to put all file names in a text file, and then accept that text file as your program's input.
2.- You should allow user to pick the directory. Then you list all the files and let them select as many files, there will not be any problem.
3.- You may have to use a
FolderBrowserDialog
instead and then useIO.Directory.GetFiles
, which works properly.