The control extender library contains three components:
provides a ListView control with sorting capabilities.
provides a ListView control with editing capabilities.
provides a ListBox control with editing capabilities.
To note here is that ListViewExSort shows the sort up/down arrows only under XP, because it uses functionality from comctrl version 6.0 which is only distributed with XP.
From two projects I had two different classes which inherited from listview to extend its functionality. I felt that merging the two classes into one was not the right approach. Fortunately, I found the article ListViewSortManager control by Eddie Velasquez which gave me the idea not to inherit but to 'extend' listviews functionality.
Using the code
To use the extender controls, they have to be added to the toolbox first. The extenders can then be dropped onto a form where they will show up in the component tray. They can then be configured by setting the appropriate properties.
The image below shows the properties for
The most important property is the control that the extender is associated with. This can also be coded manually like:
The only property that can't be set with the designer is
comparer. By default (if no comparers are provided) the columns will be sorted as a case-sensitive string. If sorting should be performed by something else, a custom sorter must be provided. The following code shows how to code a number comparer:
class Int32Comparer : IListViewComparer
public int OnCompare(string x, string y)
return int.Parse(x, NumberStyles.Number) -
The comparer class must be attached to the listview extender as follows:
The sample above will sort the second column by number and all other columns by text.
Points of Interest
What's not so obvious, is that
ListBoxExEdit supports key-naviagtion. It is switched off by default. The following code enables it:
this.listBoxExEdit1.KeyNavigation = true;
Also note that the followging key-mappings are hardcoded into the library:
||Insert a new line above the currently selected line|
||Delete the selected line|
||Move the selected line down|
||Move the selected line up|
The sample project is for VS.NET 2003. Fortunately, there is a project available that converts 2003 files back to VS.NET.
A converted project will fail to compile on
EnableVisualStyles is only available in .NET 1.1. This line can be removed but the xp-look will then not be available.
The control extender library is not yet ready to be used in all kinds of projects. Parts of it are hardly tested and I expect it to fail in ways I've never tested it before. For me, these three controls are useful and I intend to improve functionality and reliability as I work with them. I hope that there are some people out there that can live with the limited functionality and can give me feedback on how to improve.
- Initial Release: July 6, 2003