Click here to Skip to main content
16,016,391 members
Articles / Programming Languages / Visual Basic

Files Selection Dialog Box / Tree

Rate me:
Please Sign up or sign in to vote.
4.19/5 (19 votes)
8 May 2007CPOL2 min read 55.8K   1.1K   26   11
A treeview dialog box.

Screenshot - Article.gif

Introduction

The problem we need to solve is this: programmers are not allowed to inherit file dialog boxes in VB.NET 2005 and there are two kinds: open and save.

I once made an encryption program that worked like a safe for personal data. In my program, there were buttons named import and export, and I thought it was ugly to use dialogs with buttons whose captions were save, open. Sometimes we need to change button captions in certain situations. This project is good for those who want to design a customized file dialog box. It contains an implementation of three "tree view" file dialog boxes. The first one uses the Microsoft files-folders tools. The second one is a simple dialog that will show a file description of any file you select. The third one is a rich dialog with a progress bar, movable menu, status bar, and multiple view choices: details ,list, large icons ...

Background

A basic knowledge of the language and tree-list view controls.

Using the code

Import all the code files of the dialog you like in your project and just handle the files in the code of the "Proceed" button instead of showing the messagebox. I will not explain everything here, but only the headlines: when you load the form, the program will use Directory.GetLogicalDrives to get all the drives in your computer and will add them in the tree view control. An image list is needed here to set the small icons for the list of drives. Now we will need a procedure to get a level of folders to handle the click on any node (after the select event). This procedure will take the name of the node (the drive or the folder) and will display the children of this node according to the names of the nested folders of the drive or folder, and will display the files in the list view control. Two image lists are needed here because of the two views (large icons, small icons), and you must bind them to the list control. Here are the main procedures:

VB
' this will generate one level of folders in the tree node
' itree is the mother node and path is logical path
' on hard disk that this node stands for.
 
Sub printfilesfolders_here(ByVal path As String, ByRef itree As TreeNode) 
    Dim foldername As String 
    Dim filename As String 
    itree.Nodes.Clear() 
    On Error GoTo eee 

    For Each foldername In Directory.GetDirectories(path)
        ''take the name of folders in the folder or drive
        On Error GoTo eee 
        Dim jj = foldername.LastIndexOf("\") 
        Dim jj1 = foldername.Length - jj 
        'separate the name from the path
        Dim foldr = foldername.Substring((jj + 1), (jj1 - 1))
        itree.Nodes.Add(foldr, foldr) 'add only the name
    Next
    Exit Sub
eee: 
End Sub

'this will display files in the list view according to the path of the mother node

Sub displayfiles(ByVal path As String)
' it uses for each  on Directory.GetFiles 
' to take the pathes of files and then it gets 
' only the names and adds them in the list
' we use AddRange instead of add to gain the details view in the list

Points of Interest

If you shell the dialog after you add a USB flash disk or a new network place, they will not appear, so you need to plan to add a refresh button.

History

  • Last updated: 2-4-2007.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
GeneralNIcely Done Pin
apache1o11-Jun-07 22:48
apache1o11-Jun-07 22:48 
QuestionI have a private question Pin
commandant_.16-May-07 3:40
commandant_.16-May-07 3:40 
Generalyou are extremely bright [modified] Pin
commandant_.16-May-07 3:35
commandant_.16-May-07 3:35 
QuestionWhat abt VS 2003 Pin
Pradeep Sen14-May-07 20:11
Pradeep Sen14-May-07 20:11 
AnswerRe: What abt VS 2003 Pin
Alaa Jubran15-May-07 9:35
Alaa Jubran15-May-07 9:35 
Mad | :mad:

You trust yourself too mush, don't you?

What makes you believe that I was interested in your code?

And if you was a good .net programmer you would realize (if you bothered yourself a little bit to see

my other articles) that this is the easiest code I posted , and human logic would say:

if I am able to do the code of those articles then making a stupid tree dialog will not be a problem to me.

Believe it or not I made that dialog in lesser than 5 days, during the 5 days I was working with other

stuff too, and about the .net 2003, I abandoned that long time ago because it is before lord Jesus, and

I never look at any code from prior versions unless it is a miracle, while your case is subnormal.

When I was studying in my collage our courses were as advanced as those in US

We were supervised by doctors graduated from best Colleges and institutions in Europe

and in full day work for 5 years they teach a lot

(C/C++) -Java –Database (Sql-Oracle)

UML– Intelligent Search Algorithms- Operating Systems

Compiler Theory-Neural Networks

Knowledge based systems – Virtual Reality- Parallel Programming

Multimedia and Hypermedia -Natural Languages Processing - Computer Vision

Robotics – Cryptography - Machine Learning -Genetic Algorithms, Fuzzy Logic

Expert Systems - Data mining and more.
And for every subject we had at least one assignment (code).

And because my best hobby is programming, I wrote, beside that, dozens of programs

Man… if you think that some reasonable man would thing to steal a tree dialog from you then

I feel pity for you and him.

Now I intend to post articles (in this year and up to my free time) about this:

- Text in Text Steganography

-The generalized GA theory: holding real values in chromosomes

-Robot control or OCR app or Animating and Processing Multilayer Architecture.

-Crossword puzzle generation from oracle db.

I just hope that you will not say that you programmed them too.







My articles are dedicated to Dr. Ihab Jubran (my brother).

Generalrequest: Pin
Rola /anglian/8-May-07 21:58
Rola /anglian/8-May-07 21:58 
GeneralRe: request: Pin
Alaa Jubran8-May-07 23:16
Alaa Jubran8-May-07 23:16 
GeneralRe: request: Pin
Alaa Jubran8-May-07 23:17
Alaa Jubran8-May-07 23:17 
Generalgreat! Pin
Rola /anglian/8-May-07 21:50
Rola /anglian/8-May-07 21:50 
Questionwould you? Pin
Andromeda ..8-May-07 21:11
Andromeda ..8-May-07 21:11 
AnswerRe: would you? Pin
Alaa Jubran8-May-07 23:15
Alaa Jubran8-May-07 23:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.