Windows Develop Bookmark and Share   
 index > Windows Forms Designer > My Data Binding Solution for a "Browse for Drive" Dialog Box
 

My Data Binding Solution for a "Browse for Drive" Dialog Box

Hello everyone.  This is not a question, just a post.  Feel free to comment or whatever.  The intent here is to show you guys what YOU helped me build in the past couple of months.  It is not perfect, but works nicely so far.

I had the need for a Browse for Drive dialog box that showed only removable disks.  The DriveInfo.GetDrives() method returns a list, and I can check the drive's type.  Well, USB-connected drives that are based on an actual hard disk drive appear as Fixed !  I needed those to show as removable!  So I created the DrivesDataSource component (an instance shown in figure 1 ).  This one is capable of telling apart the "fixed" hard disk drives that are removable.

Then I wanted a really nice way of presenting them.  I found @ codeproject.com a TreeView for folders.  It had code to retrieve the OS' images, which I thought it was really nice.  This one also worked under the idea of a "data source", but it was its own propietary data source and not a .Net-standardized data source (actually, this code gave me the idea of creating my custom collection of drives as a data source).  So I took out the code that I needed for retrieving the images and moved on to modifying the provided, stock ListView .

CodeProject.com also offered a data-bound ListView , but it was "hardcoded" to work with DataSets only.  Still, it became the starting point.  Juggling around for weeks with different testing and debugging, voilá!, I ended up with what is seen on the figures below.  It works as well with DataSets as with any other data source, including my DrivesDataSource data source.

Actually, it works better with DrivesDataSource .  Why?  Well, a ListView is not just about the items, it is about the items' images.  DrivesDataSource provides the images too!  I defined an IListImageProvider interface.  This interface is implemented by the internal list of DrivesDataSource .  The DataBoundListView control checks for the implementation of this interface.  If there, it uses it to automatically assign the image indexes as well as the ImageList .

Again, many thanks to all that helped me out with this one.  Very much appreciated.

The Images

Figure 1 .  The DrivesDataSource exposing the custom smart tags.  Note how my list of drive types is longer than the stock one used by DriveInfo .  Also note the standard DataGridView control just below the DataBoundListView .  Both are bound to the same DrivesDataSource component.

Figure 2 .  This is the designer of DataBoundListView showing the use of the rich .Net type editors for data binding.  The list is the list of the public properties of my Drive class, which is the type of the items contained in the bound collection.

Figure 3 .  This is the collection editor showing the additional DataField property.  It also uses one of the rich .Net editors to display a list of properties exposed by the data-bound item.  Actually, for this one to work, the new column header class needs to lie about having a DataSource property when in fact it does not.

MCP
webJose  Wednesday, October 07, 2009 11:38 PM
Looks good.

Thanks for sharing!

Regards,
Jie
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

If you have any feedback, please tell us.

The CodeFx Project
My Blog (in Simplified Chinese)
Wang, Jie  20 hours 16 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• Dynamically Designing and Saving Windows Forms, with data?
• visibility of controlls while editing.
• Making a dataGridView with more "columns"
• Hidden Fields
• Positioning Tools in the html Designer
• DataGridColumnStyle Button Control
• How do I pop up/show a form at the mouse coordinates - like a context menu?
• VS2005 RTM - grid/guide toggling broken
• \field command are deleting in RichTextBox
• move cursor right in datagridview