Click here to Skip to main content
12,633,417 members (30,457 online)
Click here to Skip to main content
Add your own
alternative version

Stats

189.8K views
2.9K downloads
85 bookmarked
Posted

VB.NET TreeListView

, 18 Dec 2003 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

SimonCampbell
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 20:50
memberaravindkottapalli20-Jun-12 20:50 
GeneralMy vote of 5 Pin
Member 442549513-Dec-10 1:21
memberMember 442549513-Dec-10 1:21 
QuestionNo images? Pin
Frederik768-Mar-09 7:57
memberFrederik768-Mar-09 7:57 
GeneralVB.NET Version Pin
Tosberg10-Jun-08 20:02
memberTosberg10-Jun-08 20:02 
QuestionHow to create a tree view for more than one item in ASP.net [modified] Pin
sahi3-Feb-08 23:46
membersahi3-Feb-08 23:46 
GeneralNode height property Pin
virtual.aussie23-Jan-08 8:09
membervirtual.aussie23-Jan-08 8:09 
GeneralLines of the Tree Pin
piolasoclau28-Dec-07 12:23
memberpiolasoclau28-Dec-07 12:23 
GeneralSelectedNode trouble in vb.net Pin
Ebjora21-Jun-07 1:57
memberEbjora21-Jun-07 1:57 
QuestionRe: SelectedNode trouble in vb.net Pin
KA National Marker22-Oct-07 5:12
memberKA National Marker22-Oct-07 5:12 
GeneralRe: SelectedNode trouble in vb.net Pin
piolasoclau13-Nov-07 7:40
memberpiolasoclau13-Nov-07 7:40 
GeneralNew TreeListView coming soon Pin
Tosberg17-Jun-07 14:49
memberTosberg17-Jun-07 14:49 
GeneralRe: New TreeListView coming soon Pin
gnosbush20-Nov-07 18:02
membergnosbush20-Nov-07 18:02 
GeneralRe: New TreeListView coming soon Pin
irish809618-Dec-07 8:06
memberirish809618-Dec-07 8:06 
GeneralRe: New TreeListView coming soon Pin
logan133719-Dec-07 6:37
memberlogan133719-Dec-07 6:37 
QuestionRe: New TreeListView coming soon Pin
cnieva17-Mar-08 9:55
membercnieva17-Mar-08 9:55 
AnswerRe: New TreeListView coming soon Pin
Tosberg5-Jun-08 15:50
memberTosberg5-Jun-08 15:50 
QuestionCompact Framework Anyone? Pin
y2khines15-May-07 13:46
membery2khines15-May-07 13:46 
GeneralKudos Pin
myName4-Mar-07 9:20
membermyName4-Mar-07 9:20 
GeneralRe: Kudos Pin
cnieva12-Mar-07 6:19
membercnieva12-Mar-07 6:19 
QuestionI cant get this working in VB2005 Pin
HelderPinto791-Mar-07 6:52
memberHelderPinto791-Mar-07 6:52 
AnswerRe: I cant get this working in VB2005 Pin
cnieva1-Mar-07 8:00
membercnieva1-Mar-07 8:00 
AnswerRe: I cant get this working in VB2005 Pin
HelderPinto791-Mar-07 22:53
memberHelderPinto791-Mar-07 22:53 
GeneralRe: I cant get this working in VB2005 Pin
cnieva2-Mar-07 5:28
membercnieva2-Mar-07 5:28 
GeneralRe: I cant get this working in VB2005 Pin
yusuf01107-Nov-07 4:46
memberyusuf01107-Nov-07 4:46 
GeneralRe: I cant get this working in VB2005 Pin
cnieva7-Nov-07 12:08
membercnieva7-Nov-07 12:08 
QuestionAnyway of adding a progressbar to one of the columns? Pin
dellams200726-Feb-07 14:25
memberdellams200726-Feb-07 14:25 
QuestionHow to add image in the treelistview [modified] Pin
D.N.R26-Dec-06 21:18
memberD.N.R26-Dec-06 21:18 
QuestionOrder by column? Pin
TuomoV7-Dec-06 3:48
memberTuomoV7-Dec-06 3:48 
Questionhow can I show a image in first column ? [modified] Pin
HemaSekhar6-Dec-06 22:31
memberHemaSekhar6-Dec-06 22:31 
QuestionHow to get only one selectable node Pin
TuomoV31-Oct-06 22:55
memberTuomoV31-Oct-06 22:55 
AnswerRe: How to get only one selectable node Pin
SimonCampbell31-Oct-06 22:57
memberSimonCampbell31-Oct-06 22:57 
GeneralRe: How to get only one selectable node Pin
TuomoV31-Oct-06 23:05
memberTuomoV31-Oct-06 23:05 
GeneralRe: How to get only one selectable node Pin
TuomoV1-Nov-06 0:16
memberTuomoV1-Nov-06 0:16 
GeneralRe: How to get only one selectable node Pin
cnieva22-Feb-07 15:29
membercnieva22-Feb-07 15:29 
GeneralRe: How to get only one selectable node Pin
cagriarican8-Feb-07 2:07
membercagriarican8-Feb-07 2:07 
GeneralRe: How to get only one selectable node Pin
cnieva22-Feb-07 16:20
membercnieva22-Feb-07 16:20 
QuestionCan I have for Web version? Pin
KhinLLK12-Sep-06 19:11
memberKhinLLK12-Sep-06 19:11 
GeneralCheckbox's in treeview Pin
syonin8-Sep-06 8:09
membersyonin8-Sep-06 8:09 
GeneralDynamically showing textbox on click in cell Pin
ashubhalerao28-Aug-06 2:53
memberashubhalerao28-Aug-06 2:53 
Generalrecycle bin Pin
syriast30-Jul-06 4:36
membersyriast30-Jul-06 4:36 
QuestionTo add focused node property in treelistview Pin
irfanahsan1-May-06 2:53
memberirfanahsan1-May-06 2:53 
AnswerRe: To add focused node property in treelistview Pin
SimonCampbell1-May-06 22:37
memberSimonCampbell1-May-06 22:37 
Generalvery good, well done Pin
walid100114-Apr-06 14:06
memberwalid100114-Apr-06 14:06 
Questionhow to select complete row as one unit Pin
Rizwan Bashir17-Aug-05 0:00
memberRizwan Bashir17-Aug-05 0:00 
AnswerRe: how to select complete row as one unit Pin
cnieva22-Feb-07 16:26
membercnieva22-Feb-07 16:26 
GeneralRe: how to select complete row as one unit Pin
piolasoclau28-Dec-07 12:22
memberpiolasoclau28-Dec-07 12:22 
GeneralRe: how to select complete row as one unit Pin
cnieva29-Dec-07 12:42
membercnieva29-Dec-07 12:42 
GeneralRow Select Pin
TreyElliott3-Jan-05 4:18
memberTreyElliott3-Jan-05 4:18 
GeneralRe: Row Select Pin
cnieva22-Feb-07 16:34
membercnieva22-Feb-07 16:34 
GeneralSlow Pin
s.r.d5-Jun-04 7:11
susss.r.d5-Jun-04 7:11 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161208.2 | Last Updated 18 Dec 2003
Article Copyright 2003 by SimonCampbell
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid