HOW? OpenFileDialog Multiselect

  • Thread starter Thread starter Lee Gillie
  • Start date Start date
L

Lee Gillie

WITH MULTISELECT=FALSE: If I make a text box, which is a file path,
and have a browse button, in the browse click I can set
OpenFileDialog.FileName to the text box text. Do the Dialog, and then
restore the text box content from the OpenFileDialog.FileName.

WITH MULTISELECT=TRUE: I can see that after the Dialog I can load the
text box with VB.Join(OpenFileDialog.FileNames,";") The part I can't
see is how to get the OpenFileDialog initialized with more than one
file for the initial display.

Can it even be done?

TIA - Best Regards, Lee Gillie - Spokane, WA
 
Hi Lee Gillie,
AFAIK there is no easy way to do that. I'm not sure if this can be done at
all with the FileOpenDialog class.
What you can do is to use PInvoke and call GetOpenFileName API function.
That function accepts one scary structure (OPENFILENAME) as a parametter.
To initialize the open file dialog with more then one file you can set its
*lpstrFile* field with string of the form
"<file path>\0<file name 1>\0<file name 2>\0.......\0<file name N>\0"

My next idea (I've never tried it) is the following.
Open and Save As dialog boxes provide so called OFNHookProc. The dialog box
calls the hook sending it some messages and notifications. Along with the
WM_INITDIALOG message the dialog sends that OPENFILENAME structure. I'm not
sure but you may be able to change the *lpstrFile* field at that stage of
the dialog creation. I'm telling you that because OpenFileDialogClass gives
us te opportunity to install that hook by inheriting the OpenFileDialog
class and overriding *HookProc* virtual method.
For more info about OFNHookProc check with MSDN
ms-help://MS.MSDNQTR.2003FEB.1033/winui/winui/windowsuserinterface/userinput
/commondialogboxlibrary/commondialogboxreference/commondialogboxfunctions/of
nhookproc.htm


HTH
B\rgds
100
 
100 said:
Hi Lee Gillie,
AFAIK there is no easy way to do that. I'm not sure if this can be done at
all with the FileOpenDialog class.

I am pretty sure you are right.
What you can do is to use PInvoke and call GetOpenFileName API function.
That function accepts one scary structure (OPENFILENAME) as a parametter.
To initialize the open file dialog with more then one file you can set its
*lpstrFile* field with string of the form
"<file path>\0<file name 1>\0<file name 2>\0.......\0<file name
N>\0"

Hmmmmm... yes I think I recall having done something like the first
idea in VB6 a tong lime ago.
My next idea (I've never tried it) is the following.
Open and Save As dialog boxes provide so called OFNHookProc. The dialog box
calls the hook sending it some messages and notifications. Along with the
WM_INITDIALOG message the dialog sends that OPENFILENAME structure. I'm not
sure but you may be able to change the *lpstrFile* field at that stage of
the dialog creation. I'm telling you that because OpenFileDialogClass gives
us te opportunity to install that hook by inheriting the OpenFileDialog
class and overriding *HookProc* virtual method.
For more info about OFNHookProc check with MSDN
ms-help://MS.MSDNQTR.2003FEB.1033/winui/winui/windowsuserinterface/use
rinput
/commondialogboxlibrary/commondialogboxreference/commondialogboxfuncti
ons/of
nhookproc.htm

Wow, TWO ideas... and I was pretty much DEAD IN THE WATER on this.
This second one looks intriguing. Not sure which route I will go on
this yet, but If I attempt this, I will report back my findings.
HTH
B\rgds
100

Yes it does. Thanks a million. Best regards, Lee
 
Back
Top