Click here to Skip to main content
Licence CPOL
First Posted 4 Dec 2003
Views 148,564
Downloads 898
Bookmarked 81 times

VB.NET TreeListView

By | 18 Dec 2003 | Article
A Treeview/Listview hybrid, inheriting from Control, all custom drawn...

Introduction

Firstly, I'd like to mention that this code is still in its infancy, so you might find the odd (!) bug, or something that is done in an unusual way!

If you DO find bugs, or have any comments about ways to improve, please don't hesitate to mail me.

Needing a Treeview that is very flexible, and easily customizable, I first tried to inherit from the standard TreeView control shipped with .NET. Immediately I came across several problems which I couldn't find a satisfactory work-around to, which led me to look into the feasibility of writing a TreeView which inherits from Control, and do all the painting myself. Well at first glance, it’s not too much of a problem - I started out by trying a custom drawn ListView, which was fairly straightforward, so how much more difficult can a TreeView be...!?

Using the code

Ok, well I wanted these classes to be as scalable as possible, so I first created:

Public MustInherit Class View
    Inherits Control

This View class handles the basic stuff that would be common across any tree/list type controls that inherit from it.

  • It maintains a collection of columns
  • It handles the drawing of the column headers, borders, etc.
  • It provides a Protected MustOverride Sub DrawItems(ByVal g As Graphics, ByVal r As Rectangle)
  • It has two variables TotalHeight and TotalWidth, which are used for setting scrollbars.
  • TotalHeight Must be maintained by inheritors in their DrawItems method.
  • TotalWidth Is maintained by the View class, because it knows about it's own collection of columns.

The best way for you to get to grips with it is to download it!

Points of Interest

I've had some fun doing this, and learnt a lot about how to paint a control myself. I've tried to avoid contrived code, and done my best to keep everything as pure as possible. I'm a big believer that if you have to do a quick & dirty fix, it'll come back and haunt you later...!

Strange as it may seem, I found Microsoft Paint extremely useful while coding this... It was so useful to be able to do a screen print, and then use Paint to zoom in and have a look at how accurate my Paint code was...!

Planned Updates

I'm hoping to add in the drawing of root lines, and also the ability to have icons on each node.

History

  • 4-Dec-03 - First release.
  • 18-Dec-03 - Zip updated.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

SimonCampbell

Software Developer (Senior)

United Kingdom United Kingdom

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 PinmemberMember 44254950:21 13 Dec '10  
QuestionNo images? PinmemberFrederik766:57 8 Mar '09  
GeneralVB.NET Version PinmemberTosberg19:02 10 Jun '08  
QuestionHow to create a tree view for more than one item in ASP.net [modified] Pinmembersahi22:46 3 Feb '08  
GeneralNode height property Pinmembervirtual.aussie7:09 23 Jan '08  
GeneralLines of the Tree Pinmemberpiolasoclau11:23 28 Dec '07  
GeneralSelectedNode trouble in vb.net PinmemberEbjora0:57 21 Jun '07  
QuestionRe: SelectedNode trouble in vb.net PinmemberKA National Marker4:12 22 Oct '07  
GeneralRe: SelectedNode trouble in vb.net Pinmemberpiolasoclau6:40 13 Nov '07  
GeneralNew TreeListView coming soon PinmemberTosberg13:49 17 Jun '07  
GeneralRe: New TreeListView coming soon Pinmembergnosbush17:02 20 Nov '07  
GeneralRe: New TreeListView coming soon Pinmemberirish80967:06 18 Dec '07  
GeneralRe: New TreeListView coming soon Pinmemberlogan13375:37 19 Dec '07  
QuestionRe: New TreeListView coming soon Pinmembercnieva8:55 17 Mar '08  
Hi,
Do you have any news about your control?
Thanks,
 
Cristian
AnswerRe: New TreeListView coming soon PinmemberTosberg14:50 5 Jun '08  
QuestionCompact Framework Anyone? Pinmembery2khines12:46 15 May '07  
GeneralKudos PinmembermyName8:20 4 Mar '07  
GeneralRe: Kudos Pinmembercnieva5:19 12 Mar '07  
QuestionI cant get this working in VB2005 PinmemberHelderPinto795:52 1 Mar '07  
AnswerRe: I cant get this working in VB2005 Pinmembercnieva7:00 1 Mar '07  
AnswerRe: I cant get this working in VB2005 PinmemberHelderPinto7921:53 1 Mar '07  
GeneralRe: I cant get this working in VB2005 Pinmembercnieva4:28 2 Mar '07  
GeneralRe: I cant get this working in VB2005 Pinmemberyusuf01103:46 7 Nov '07  
GeneralRe: I cant get this working in VB2005 Pinmembercnieva11:08 7 Nov '07  
QuestionAnyway of adding a progressbar to one of the columns? Pinmemberdellams200713:25 26 Feb '07  

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.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 18 Dec 2003
Article Copyright 2003 by SimonCampbell
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid