Click here to Skip to main content
14,037,763 members
Click here to Skip to main content
Add your own
alternative version


85 bookmarked
Posted 4 Dec 2003
Licenced CPOL

VB.NET TreeListView

, 18 Dec 2003
Rate this:
Please Sign up or sign in to vote.
A Treeview/Listview hybrid, inheriting from Control, all custom drawn...


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.


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


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


About the Author

Software Developer (Senior)
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionSelected node text Pin
aravindkottapalli20-Jun-12 19:50
memberaravindkottapalli20-Jun-12 19:50 
GeneralMy vote of 5 Pin
Member 442549513-Dec-10 0:21
memberMember 442549513-Dec-10 0:21 
QuestionNo images? Pin
Frederik768-Mar-09 6:57
memberFrederik768-Mar-09 6:57 
GeneralVB.NET Version Pin
Ted Osberg10-Jun-08 19:02
memberTed Osberg10-Jun-08 19:02 
QuestionHow to create a tree view for more than one item in [modified] Pin
sahi3-Feb-08 22:46
membersahi3-Feb-08 22:46 
GeneralNode height property Pin
virtual.aussie23-Jan-08 7:09
membervirtual.aussie23-Jan-08 7:09 
GeneralLines of the Tree Pin
piolasoclau28-Dec-07 11:23
memberpiolasoclau28-Dec-07 11:23 
GeneralSelectedNode trouble in Pin
Ebjora21-Jun-07 0:57
memberEbjora21-Jun-07 0:57 
QuestionRe: SelectedNode trouble in Pin
Smokeywade22-Oct-07 4:12
memberSmokeywade22-Oct-07 4:12 
GeneralRe: SelectedNode trouble in Pin
piolasoclau13-Nov-07 6:40
memberpiolasoclau13-Nov-07 6:40 
GeneralNew TreeListView coming soon Pin
Ted Osberg17-Jun-07 13:49
memberTed Osberg17-Jun-07 13:49 
GeneralRe: New TreeListView coming soon Pin
twinsfan20-Nov-07 17:02
membertwinsfan20-Nov-07 17:02 
GeneralRe: New TreeListView coming soon Pin
irish809618-Dec-07 7:06
memberirish809618-Dec-07 7:06 
GeneralRe: New TreeListView coming soon Pin
chaiguy133719-Dec-07 5:37
memberchaiguy133719-Dec-07 5:37 
QuestionRe: New TreeListView coming soon Pin
cnieva17-Mar-08 8:55
membercnieva17-Mar-08 8:55 
AnswerRe: New TreeListView coming soon Pin
Ted Osberg5-Jun-08 14:50
memberTed Osberg5-Jun-08 14:50 
QuestionCompact Framework Anyone? Pin
y2khines15-May-07 12:46
membery2khines15-May-07 12:46 
GeneralKudos Pin
Technorodent4-Mar-07 8:20
memberTechnorodent4-Mar-07 8:20 
GeneralRe: Kudos Pin
cnieva12-Mar-07 5:19
membercnieva12-Mar-07 5:19 
QuestionI cant get this working in VB2005 Pin
HelderPinto791-Mar-07 5:52
memberHelderPinto791-Mar-07 5:52 
AnswerRe: I cant get this working in VB2005 Pin
cnieva1-Mar-07 7:00
membercnieva1-Mar-07 7:00 
AnswerRe: I cant get this working in VB2005 Pin
HelderPinto791-Mar-07 21:53
memberHelderPinto791-Mar-07 21:53 
GeneralRe: I cant get this working in VB2005 Pin
cnieva2-Mar-07 4:28
membercnieva2-Mar-07 4:28 
GeneralRe: I cant get this working in VB2005 Pin
yusuf01107-Nov-07 3:46
memberyusuf01107-Nov-07 3:46 
GeneralRe: I cant get this working in VB2005 Pin
cnieva7-Nov-07 11:08
membercnieva7-Nov-07 11:08 

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.

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