Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

File and Folder ListView

0.00/5 (No votes)
4 May 2012 1  
File and Folder Listview is a simple component that I made as an alternative to OpenFileDialog or CommonOpenFileDialog that does not support selecting both File or Folder.

 

Introduction

File and Folder Listview is a simple component that I made as an alternative to OpenFileDialog or CommonOpenFileDialog that does not support selecting both File or Folder.

In the standard controls, we use OpenFileDialog to select Files and we use FolderDialog to select Folders. Other common controls released by Microsoft was the CommonOpenFileDialog available in WindowsAPICodePack. The UI looks like the standard OpenFileDialog but it can also select Folders if "IsFolderPicker" property is set to true. But one thing these standard controls cannot do is to the ability to select both File or Folder 

Using the code

In your project, add FileFolderList.cs and drag the control in your form or in any container. FileFolderList is using ListView as it's base class so all the properties, method, and events of the ListView are available.

FileFolderList has 3 custom properties

  • string DefaultPath {get;set;}
  • string SelectedPath {get;}
  • bool isSoloBrowser {get;set;}
    // - when true, it will add "..." so you can go back to the parent folder

and 2 custom methods

  • void Load()
    call this method when your form has loaded 
  • void Browse(string path)  

Adding the control programatically can be done in this way

GCS.Windows.Forms.FileFolderList ffl = new GCS.Windows.Forms.FileFolderList();
ffl.View = View.Details;
ffl.Load();
ffl.Dock = DockStyle.Fill;
this.Controls.Add(ffl); 

Points of Interest

FileFolderList uses BackgroundWorker object to load the associated icons in a separate thread. 

History

this is my initial release 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here