Click here to Skip to main content
Click here to Skip to main content

ControlExtender Library

, 5 Jul 2003
Rate this:
Please Sign up or sign in to vote.
A component that enhances standard ListView and ListBox controls. (full designer support)

Sample Image - extendertest.png

Introduction

The control extender library contains three components:

  • ListViewExSort
    provides a ListView control with sorting capabilities.
  • ListViewExEdit
    provides a ListView control with editing capabilities.
  • ListBoxExEdit
    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.

Background

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 ListViewExSort.

ListView Properties

The most important property is the control that the extender is associated with. This can also be coded manually like:

listViewExSort1.ListView=listView1;

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)
    {
        try
        {
            return int.Parse(x, NumberStyles.Number) - 
                                int.Parse(y, NumberStyles.Number);
        }
        catch (System.Exception)
        {
            return -1;
        }
    }
}

The comparer class must be attached to the listview extender as follows:

listViewExSort1.Comparer=new IListViewComparer[]
   {
      null,    
      new Int32Comparer(),
   };

The sample above will sort the second column by number and all other columns by text.

Points of Interest

Key Navigation

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:

Ctrl-Insert - Insert a new line above the currently selected line
Ctrl-Delete - Delete the selected line
Ctrl-Down - Move the selected line down
Ctrl-Up - Move the selected line up

VS.NET

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

Application.EnableVisualStyles(); // .NET 1.1 only

because EnableVisualStyles is only available in .NET 1.1. This line can be removed but the xp-look will then not be available.

Final Note

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.

History

  • Initial Release: July 6, 2003

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

About the Author

Reto Ravasio

Switzerland Switzerland
No Biography provided

Comments and Discussions

 
QuestionExtending a listbox with a progressBar Control PinmembereRRaTuM17-May-06 5:41 
Generalerror Pinmemberjuli80243-May-05 22:15 
QuestionHow to use the LIstViewExEdit PinsussAnonymous13-Apr-05 23:01 
AnswerRe: How to use the LIstViewExEdit PinmemberReto Ravasio15-Apr-05 8:50 
GeneralRe: How to use the LIstViewExEdit Pinmemberjuli802416-Apr-05 4:11 
GeneralRe: How to use the LIstViewExEdit PinmemberReto Ravasio17-Apr-05 4:33 
GeneralRe: How to use the LIstViewExEdit Pinmemberjuli802418-Apr-05 21:48 
Hello,
Even if I change the both columns properties to IsEdit=false I still can edit the forst column(only) - so it seems that the listview is not "connected" correctly to the listViewExEdit.
How can I solve this?
Thanks a lot!
GeneralAscending Descending Arrow Pinmembershakhshir3-Apr-05 5:51 
GeneralRe: Ascending Descending Arrow PinmemberReto Ravasio3-Apr-05 12:00 
GeneralProgress Bar in ListView PinmemberBluetears21-Sep-03 4:17 
GeneralHideSelection Bug PinmemberYoeri12-Jul-03 22:42 
GeneralRe: HideSelection Bug PinmemberReto Ravasio14-Jul-03 8:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 6 Jul 2003
Article Copyright 2003 by Reto Ravasio
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid