Wednesday, January 23, 2008

Windows Explorer in C#

This is the first in a series of articles demonstrating how to create an


To Get the code Mail us at :- codes.jinesh@gmail.com
And join our community :- Mad Engineerss...!




Introduction
This is the first in a series of articles demonstrating how to create an Explorer-like application. The program uses the following controls: TreeView, ListView, Splitter, MainMenu, StatusBar, Panel, ImageList, and ColumnHeaders for the ListView. Many of the properties are set using the designer, so I would suggest that you download the project, unless of course you are not a beginner.


The program demonstrates the following:
How to read files and directories from disk, using the DirectoryInfo instance class.
How to populate nodes in a TreeView Control.
How to populate the ListView Control.
How to use a basic StatusBar.
How to use the After_Select Event of the TreeView Control.
How to use the Item_Activate Event of the ListView Control.
How to use the Load Event of the Form itself.


What I think is best about this program

1. It is a simple design, which should help you to learn how to use the TreeView Control, It took four revisions.
2. Compared to many of the other sample or demo programs available, it loads files and directories fast!
3. The program only loads the necessary files and folders, not the entire directory tree like many demos do.
4. The TreeView's Tag property is entirely unused in this implementation, leaving you a place to put something.
5. There is only one event, and two methods which drive the TreeView control.
6. This program uses a minimal amount of string chopping, unlike many other demos in it's class.


In closing
This program is designed to show the basics to the beginner, experts will have to wait until I become an expert! There are too many hard decisions to make when designing an Explorer Interface. So I have made some trade offs to keep the code as readable as possible. I plan to remove the "hard coded" stuff in future releases.

One of the hardest decisions was to start the root directories at the Drive level instead of nesting under the Desktop\MyComputer nodes, which is what Windows Explorer does. You will also notice that I have turned off the "+" and "-" indicators on the TreeView, this was by design as the code to make this work properly is pretty complex for a beginner, not too mention doubling the code.


I am disappointed that .NET does not have an easy way (maybe there is) too determine the type of drives attached to the computer. I wanted to use PInvoke, but I figured I would do that in another series or update.