Click here to Skip to main content
15,350,730 members
Articles / Programming Languages / C#
Posted 30 Sep 2003


97 bookmarked

Updated Extended ListView

Rate me:
Please Sign up or sign in to vote.
4.63/5 (24 votes)
30 Sep 20033 min read
An update to Jon Rista's treeview/listview control


This posting is to update an existing posting by someone else (ContainerListView and TreeListView: Writing VS.NET design-surface compatible controls). The previous post by Jon Rista was a great foundation but inevitably, it had bugs. As Jon doesn't seem to be maintaining his post, I thought I'd help some of the people who originally downloaded his control, to be able to use a version that has the bugs I've found, fixed.

Please note that the code attached to this article has been modified using VS.NET 2003. If you want to use the code in the earlier version of VS.NET, you will need to create new .csproj and .sln files.

Why fix this control?

There are several other TreeView/ListView combo controls posted to Code Project, so why fix this one? The attraction of the control, to me, is that it is entirely in C#. We are developing an application and want to deliver a product that is all managed C# code. Most of the other implementations combine the existing TreeView and ListView controls and these, in our view, have three main draw backs:

  • They are COM, not managed code
  • The source is not available, so the appearance is determined by the authors (MS) not us
  • They were not designed to be used side-by-side

Another attraction is that Jon included hooks for the ability of the tree nodes to be composed of other objects. These might be a ListView with a different set of columns, another TreeView or a TextBox. Pretty visionary!

What has been fixed?

We noticed several bugs:

  1. The column titles were sized and displayed incorrectly (you can see this in the images presented in Jon's article
  2. The control Jon devised allows a user to include another control, however the painting of the embedded control was not always correct
  3. The mouse and keyboard movement had focus problems and, under some circumstances, the focus row would jump rows

Addressing these issues, especially the the mouse and keyboard event handling, has meant fairly substantial changes.

In his original article, Jon pointed out that the drawing routine called by the paint method was inefficient. This is because the routine computed the rows to show in the viewport by counting the rows each time. This is not an issue on a small or entirely collapsed list, but is an issue with larger lists. Addressing this issue has, again, meant fairly substantial changes. For example, the drawing routine is almost entirely rewritten and this was necessary because of the way the display size is now handled.

Now when a node is added or an existing node is expanded, collapsed or removed, its parents are notified and so they are able to maintain a note of the number of descendent nodes and the number of them that are expanded. The new drawing routine uses this additional information to workout what to draw and can do so more efficiently. The drawing routine, which is called often, is no longer affected by the length of the list as the work to maintain the node counts occurs as nodes are added, removed, expanded or collapsed.

While these changes will help performance, they can slow the process of creating the tree list in the first place. To address this, the control now exposes a BeginUpdate() method that can be called prior to adding any significant number of items. When the EndUpdate() method is called, the node values are recomputed and the control can be displayed.

Is this control now perfect?

Probably not. In fact in getting ready to post this article, I think I saw a bug that occurs when a call to ExpandAll() is used more than once. We intend to use this control (we've not done so yet), so please let me have a note of any issues you find. If you do report any problems, please make sure you tell me where to find the problem. If you have a program that illustrates the problem, please send it to me.


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

Bill Seddon
Web Developer
United Kingdom United Kingdom
Independent software development for clients including Microsoft. Design and development of modules for financial reporting and business intelligence.

Comments and Discussions

GeneralRe: Bug in Nodes.Clear() Pin
cchisho2-Mar-04 10:22
Membercchisho2-Mar-04 10:22 
GeneralRe: Bug in Nodes.Clear() Pin
Aditya Pendharkar19-Feb-07 21:15
MemberAditya Pendharkar19-Feb-07 21:15 
Generalproblem Pin
Siow Thian Choong7-Dec-03 19:06
MemberSiow Thian Choong7-Dec-03 19:06 
Generalbug on changing control Pin
Joaquin Grech (Creative1)28-Nov-03 7:25
MemberJoaquin Grech (Creative1)28-Nov-03 7:25 
GeneralRe: bug on changing control Pin
Joaquin Grech (Creative1)28-Nov-03 9:02
MemberJoaquin Grech (Creative1)28-Nov-03 9:02 
GeneralComboBox in ContainerListView sub items Pin
jiGGaK27-Nov-03 8:02
MemberjiGGaK27-Nov-03 8:02 
GeneralRe: ComboBox in ContainerListView sub items Pin
jiGGaK28-Nov-03 7:15
MemberjiGGaK28-Nov-03 7:15 
GeneralRe: ComboBox in ContainerListView sub items Pin
Hamid Qureshi26-Apr-04 2:31
MemberHamid Qureshi26-Apr-04 2:31 
Hey any solution to the ComboBox problem from the author yet or should i go with jiGGaK's workaround?
GeneralGetNodeAt Implementation Pin
codekaizen24-Nov-03 16:56
Membercodekaizen24-Nov-03 16:56 
GeneralRe: GetNodeAt Implementation Pin
Steve Dinn7-Aug-04 6:58
MemberSteve Dinn7-Aug-04 6:58 
Generalerror after doubleclick on header-sep Pin
grossbommi18-Nov-03 0:21
Membergrossbommi18-Nov-03 0:21 
GeneralRe: error after doubleclick on header-sep Pin
Jon Rista20-Nov-03 16:06
MemberJon Rista20-Nov-03 16:06 
GeneralRe: error after doubleclick on header-sep Pin
alc_aardvark28-Apr-04 3:01
Memberalc_aardvark28-Apr-04 3:01 
GeneralOriginal Update Soon Pin
Jon Rista13-Nov-03 15:32
MemberJon Rista13-Nov-03 15:32 
GeneralRe: Original Update Soon Pin
alc_aardvark28-Apr-04 4:16
Memberalc_aardvark28-Apr-04 4:16 
GeneralRe: Original Update Soon Pin
jake.stateresa5-May-05 1:23
Memberjake.stateresa5-May-05 1:23 
GeneralRe: Original Update Soon Pin
Anonymous7-May-05 18:46
MemberAnonymous7-May-05 18:46 
Questionhow to lock list? Pin
Joaquin Grech (Creative1)10-Nov-03 13:21
MemberJoaquin Grech (Creative1)10-Nov-03 13:21 
AnswerRe: how to lock list? Pin
Jon Rista14-Nov-03 12:50
MemberJon Rista14-Nov-03 12:50 
Generalbug in compilation Pin
Joaquin Grech (Creative1)10-Nov-03 6:14
MemberJoaquin Grech (Creative1)10-Nov-03 6:14 
GeneralDrag of second column (in demo) does not overlay icons in first column Pin
Michael Cooper24-Oct-03 5:15
MemberMichael Cooper24-Oct-03 5:15 
GeneralRe: Drag of second column (in demo) does not overlay icons in first column Pin
Anonymous24-Oct-03 9:04
MemberAnonymous24-Oct-03 9:04 
GeneralRe: Drag of second column (in demo) does not overlay icons in first column Pin
Michael Cooper3-Nov-03 8:27
MemberMichael Cooper3-Nov-03 8:27 
GeneralRe: Drag of second column (in demo) does not overlay icons in first column Pin
Bill Seddon3-Nov-03 8:47
MemberBill Seddon3-Nov-03 8:47 
GeneralRe: Drag of second column (in demo) does not overlay icons in first column Pin
Michael Cooper3-Nov-03 10:41
MemberMichael Cooper3-Nov-03 10:41 

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

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