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

Updated Extended ListView

, 30 Sep 2003
Rate this:
Please Sign up or sign in to vote.
An update to Jon Rista's treeview/listview control

Introduction

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.

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

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

 
GeneralNew binary for vb.net PinmemberChefren3-May-05 19:13 
GeneralColumn draw discrepancies Pinmembersalomo21-Mar-05 2:57 
QuestionQuestion for Bill.... how to keep the progress bar visible? Pinsusskmansari18-Mar-05 9:30 
AnswerRe: Question for Bill.... how to keep the progress bar visible? PinmemberNastyCoder18-Mar-05 12:08 
AnswerRe: Question for Bill.... how to keep the progress bar visible? Pinmemberkmansari18-Mar-05 14:06 
Questionhow to create different context menus for each row in TreeListview Pinmembern4nilesh10-Mar-05 21:12 
AnswerRe: how to create different context menus for each row in TreeListview PinmemberBill Seddon10-Mar-05 21:31 
GeneralA very basic question about using this control Pinsusskmansari8-Mar-05 11:52 
GeneralControls not scrolling up Pinmemberjpeng7420-Jan-05 7:12 
GeneralRe: Controls not scrolling up PinmemberDMUck15-Feb-05 9:52 
GeneralRe: Controls not scrolling up Pinmemberntuanxb31-Aug-11 22:49 
QuestionHow to change item height PinmemberSakda12-Jan-05 5:50 
AnswerRe: How to change item height PinmemberLeeKeel21-Jun-05 11:19 
GeneralRe: How to change item height PinmemberSmall Rat7-Jun-06 11:40 
GeneralRe: How to change item height Pinmemberholastefan16-Jul-06 9:43 
AnswerRe: How to change item height PinmemberDr Memory28-Sep-06 13:55 
GeneralComboBox Pinmemberdennis3310-Nov-04 18:39 
GeneralRe: ComboBox PinsussLeeKeel11-Mar-05 8:06 
GeneralRe: ComboBox PinmemberBob Knier11-Apr-05 4:39 
GeneralRe: ComboBox PinmemberA. Raees19-Oct-07 21:22 
GeneralGet_ItemAt () method Pinmembermiamiman5-Nov-04 12:59 
GeneralNew Version Pinsussikeas6818-Aug-04 8:33 
GeneralRe: New Version PinmemberBill Seddon18-Aug-04 9:40 
GeneralNew Version Pinmemberikeas6818-Aug-04 8:31 
QuestionNode.Parent WriteOnly? PinmemberBluDog4-Aug-04 23:44 
AnswerRe: Node.Parent WriteOnly? PinmemberChefren3-May-05 19:21 
GeneralOld vs. New Pinmembercoder4rent29-Jun-04 14:33 
GeneralBackColor PinmemberRini7921-Jun-04 22:17 
AnswerRe: BackColor PinmemberHemant K Jangid29-Dec-05 2:58 
QuestionHow to add FontDialog, ColorDialog etc .. PinmemberJay_sh_s24-May-04 15:50 
GeneralBug!! SubItem Control remains visible after node collapsing PinmemberJay_sh_s24-May-04 15:28 
GeneralRe: Bug!! SubItem Control remains visible after node collapsing Pinmemberbobmwaldo2-Nov-04 7:48 
GeneralRe: Bug!! SubItem Control remains visible after node collapsing PinmemberJay_sh_s3-Nov-04 13:24 
GeneralRe: Bug!! SubItem Control remains visible after node collapsing Pinmemberjakolito4-May-05 1:06 
GeneralRe: Bug!! SubItem Control remains visible after node collapsing Pinmemberbobmwaldo4-May-05 3:20 
GeneralRe: Bug!! SubItem Control remains visible after node collapsing Pinmemberjakolito4-May-05 3:26 
GeneralRe: Bug!! SubItem Control remains visible after node collapsing Pinmemberjakolito4-May-05 4:03 
GeneralRe: Bug!! SubItem Control remains visible after node collapsing Pinmemberbobmwaldo4-May-05 4:09 
GeneralRe: Bug!! SubItem Control remains visible after node collapsing Pinmemberjakolito4-May-05 4:18 
GeneralPlease Help with SelectedNode PinmemberAgent 867-May-04 18:54 
GeneralRe: Please Help with SelectedNode Pinmemberalc_aardvark11-May-04 10:24 
GeneralRe: Please Help with SelectedNode PinmemberAgent 8613-May-04 6:55 
GeneralItemDrag event Pinmemberchris beginner3-May-04 22:17 
GeneralRe: ItemDrag event Pinmemberjakolito4-May-05 3:59 
Generalvertical scrollbar PinsussAnonymous29-Apr-04 11:14 
GeneralRe: vertical scrollbar Pinsusskmansari21-Mar-05 12:14 
GeneralRe: vertical scrollbar Pinmembernagarsoft2-Jun-05 1:40 
GeneralCannot compile the 2nd time PinmemberAstronusX4-Mar-04 12:33 
GeneralRe: Cannot compile the 2nd time Pinmembercoder4rent29-Jun-04 14:40 
GeneralRe: Cannot compile the 2nd time PinmemberDrew Noakes18-Mar-05 4:32 

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 1 Oct 2003
Article Copyright 2003 by Bill Seddon
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid