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.