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