Custom OpenFileDialog

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
Hello programmers!

I've added a new bit of coding to my application to allow some network files to be saved as links into a grid.

However...I want the OFD to be as minimal as possible. I guess I may have to create my own one, but I have never done anything like that before so wouldn't know where to start.

Basically, all I want to display is the files (I use .InitialDirectory to get the correct root folder), and an OK and cancel button.
I do not want the folder pane to the left, nor the navigational controls on the top.

Anyone done something similar or got a link to somewhere that will help with this?
...in case you're wondering, i need to minimise it for "user stupidity" :p
 
A dialog is just a form shown with ShowDialog method. Anywhere in code you can set Me.DialogResult to return, you can also assign DialogResult values to specific buttons you add to the form.

VS2005 have also a form template for dialogs you can use, Add New Item and choose 'Dialog' template.
 
Use a ListBox control? or a FileListBox control (this you have to add to Toolbox by "Choose Items.." dialog)
 
hmmm I've tried and failed....I've also looked for custom file dialogs on the net but nothing matches what I'm after.

I'm not sure how to get the contents into a listbox?

Here's a simple scenario that if someone can explain might make me understand it better:
Lets say I use a listbox...

I want the contents of c:\ listed in the listbox.
If I double click a folder, I want the listbox to display the contents of that folder (and so on).
If I click on a button, it goes back up 1 level of folder.
If I double click a file, it accepts that file and closes the dialog (so in a sense double clicking a file is the same as clicking OK)

^^ basically the same functionality as the default open file dialog but without the left hand pane and the navigational areas.

Thanks!
 
Ok, I thought you only wanted to list files (quote: "all I want to display is the files").

In this new scenario you could perhaps be better off using a ListView control, like they do in Windows Explorers files&directories pane. You also need to find code to get correct icons for files/folders so there is a possibility for user to distinguish them, or you could just use your own icons, one for files and one for directories. You also need to mark each listviewitem in a manner that you in code also is able to distinguish them.

Alternative is to use one box for directories and one for files, this is what the standard controls DirListBox and FileListBox is about.

Getting files & folders you can do with System.IO objects, for example IO.Directory.GetFiles("C:\") and IO.Directory.GetDirectories("C:\") which both returns an array of strings containing the path to each file/directory.
 
Thanks JohnH,

with your info I've managed to search, find, and successfully implement
http://msdn2.microsoft.com/en-us/library/ms171645(vs.80).aspx

However, what I now need to do is store the selected file's path as a string in a textbox.
I.E. once a user has selected the file that want from the listbox, I need the full path of this file copied to a datagrid row.

There is no instruction on the walkthrough of how to do this, so any help would be much appriciated.

Kind Regards,
 
VB.NET:
Dim filename As String = ListView1.SelectedItems(0).Text
 
thats what I thought....but that only takes the filename.

I need to record the full file path..i.e.

"c:\documents and settings\user\my documents\testdoc.doc" instead of only "testdoc.doc"

If its not possible I'm going to have to look at other alternatives again, or scrap the idea and stick with the OpenFileDialog :(
 
So where have you stored the path, then?
 
I haven't (yet) that's the bit I'm trying to work out how to do :)

EDIT - Obviously the OpenFileDialog stores the filepath....just trying to replicate that bit

I'm trying to work off http://msdn2.microsoft.com/en-us/library/1330h6a4(VS.80).aspx , I don't need to know the path of a folder in the tree view, instead I need to know the path of a file in the list view
 
When you somehow selects the directory which contents is to be displayed in listview you can store that path in a private variable. When a file is selected you can combine that path with the selected filename.
 
Back
Top