I have a open dialog which need to oepn a set of files, but the problem is when i select multiple files, the files names are accumulated at the filename box with RANDOM order. But for my program, i really need to get files in the order when i ctrl-click on them because i have to read them in order.
i tried to use string[] filenames=of1.FileNames;
however, the filenames are in random order.
what should i do
many thanks

open file dialog multislection order problem
GazCoder
Hi Danny:
I just raised a similar issue with FileDialog and HookProc.
OpenFileDialog is out of the question because this class is sealed where you cannot create a derived class. However, the base class to OpenFileDialog is FileDialog and it is not sealed.
Similar to my open issue, if you can create and implement a HookProc implementation for a class you derive from FileDialog, you can then track down the list box control and extend the defaut window style of the list box control with something like "style |= LBS_SORT;". This style option is built into windows for list boxes, so I do not think you would need anymore code.
In your HookProc, you would need to trap on the WM_NCCREATE or WM_CREATE message, look for the list box control, and the update its style to automatically sort. I think window style used to be set in the MFC within something like PreCreateWindow() which is similar to the WM_NCCREATE in the Win32 SDK. WM_NCCREATE was designed to handle special data prior to creating a window or its child controls. In VC++, resource files for dialogs could be updated and changed to compile with the LBS_SORT option. I cannot recall if windows supports changing the style of a window after its creation and at runtime. I am also trying to remember if the WM_CREATE message is given just before or just after the dialog window or controls are created or just after. It may be before because modal dialog windows also have the WM_INITDIALOG message that is sent to initialize the dialog after all windows are created; this should all be handled by the FileDialog default base class functionality.
Luis Esteban Valencia Muñoz
Before you use fileNames, you can manually sort them using Array.Sort() etc.
I hope this will help!
Best Regards,
BD_Elektrona
This is not posible with the default OpenFileDialog. You should create your own dialog to provide this funtionality.You can read directories easy, everything you need for that can be found in the System.IO namespace.
Please feel free to ask for any more information when you have problems with this solution!
marcoMB
ShakyMobo
Sorry for advert, but it seems this is possible using our Dialog Workshop .NET product. Our special CaOpenFileDialog/CaSaveFileDialog (powerful replacement of the standard Open/Save dialog components) contain SelectionChange event which is raised every time user changes selected files list in the dialog. So, comparing list of selected files before and after SelectionChange, you can build list of files in the order of Ctrl-clicks. Of course, you should preserve this list in your own structure and refresh this list on every SelectionChange event. Please visit http://www.componentage.com if you want to get more information.
Best regards,
Alex