Click here to Skip to main content
Click here to Skip to main content
Go to top

Rich Design Time Featured TreeList Control

, 9 May 2005
Rate this:
Please Sign up or sign in to vote.
A Tree like component with rich design time features.

Sample Image

Introduction

There are actually several reasons that made me start doing this:

  • There are almost no tree control samples available out there. Nothing for VB.NET.
  • There are almost no examples of rich time design support for collection of controls.
  • I needed a tree with various image sizes (for a DVD collection).
  • I hated to not be able to show PNG images correctly within a tree.
  • I wanted to go deep into a control.

I'm not saying my article or my component is great work, but at least it'll give the newbie a rough start on that matter. Of course, I would say that my work is not free! I'd like to put it as ShareYourWorkWare Wink | ;) Meaning that if someone wants to improve it, he could make the others benefit as well.

Background

This article will reflect several bits of code that were put together in a kind of complete component. Among those you'll find:

  • How to build a tree (a component that has a collection property that itself has collections, etc.)
    • Implementing a real CollectionBase property.
  • How to make a control "Design Time Enabled"
    • Using <Designer()>.
    • Inheriting from ControlDesigner.
  • Twisting the PropertyGrid.
    • Collections
    • TypeConverters
    • PropertyDescriptor
    • Implementing ICustomTypeDescriptor
  • And many more.

Re-usage

Mea culpa, I know... I've been reusing two nice piece of code that are available on the web. First of all, the great "Managed C++ Wrapper of UxTheme" from Don Kackman, and secondly, The "VisualStyles" provider from SkyBound.

The code itself

Let's try to start from somewhere.

As stated before, I wanted to write a tree control. Which is not an easy thing to do, especially if you have no clue on how to start. First, I'd thought about deriving from the original TreeView control, but I soon realized that it was not possible for what I wanted.

In fact, I needed a tree control that is able to show images that are not always of the same size. Point was: creating a DVD collection application that shows all DVDs within a tree, showing a thumbnail image of the DVD cover. I also imagined a control that could have the famous Text property as long as an "optional" description.

TreeList

This is the main component. It's derived from Control. I've read somewhere on the web that the tree is supposed to take care of all the paintings. That's how I've implemented it. The main properties of TreeList are:

  • Nodes (represents a collection of TreeListNode)
  • SelectedNode (the node currently selected)
  • PointedNode (the node currently pointed by the right mouse click).

I specified a Designer (shown below) in order to enable rich design time experience. This is how it is declared:

<Designer(GetType(TreeListDesigner))> _
Public Class TreeList Inherits Control

The Nodes property needed to have some special definition as well to see it correctly in the PropertyGrid:

Private WithEvents _Nodes As TreeListNodeCollection
    <Category("Collection"), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    Public ReadOnly Property Nodes() As TreeListNodeCollection
        Get
            Return _Nodes
        End Get
    End Property

It's gotta be using the DesignerSerializationVisibility.Content in order to be able to display it that way:

Sample Image

Notice that instead of having the traditional "(Collection)", I show the number of subnodes along with a nice (+) sign to expand it and show its internal properties.

TreeListNodeCollection

This holds a collection of TreeListNodes (it's represented as the "Nodes" property). That's its definition:

<TypeConverter(GetType(TreeListNodeCollectionConverter)), _
Editor(GetType(TreeListNodeCollectionEditor), GetType(UITypeEditor)), _
DesignTimeVisible(False), _
ToolboxItem(False), _
Serializable()> _
Public Class TreeListNodeCollection
    Inherits CollectionBase
    Implements ICustomTypeDescriptor

Notice here, the use of a TypeConverter. (That allows to show "3 node(s)" instead of "(Collection)", the user of a customized Editor avoids the problem when you have a collection of collection within a property.)

TreeListNode

This represents a node. It's inherited from Component. That was the only way to achieve a correct designer for the TreeList. It is defined that way:

<TypeConverter(GetType(TreeListNodeConverter)), _
DesignTimeVisible(False), _
ToolboxItem(False), _
Serializable()> _
Public Class TreeListNode
    Inherits Component

It also has a property called "Nodes" which represents a TreeListNodeCollection (in order to hold its child nodes).

TreeListDesigner

This is the designer of the TreeList component, it inherits from ControlDesigner and allows the user to select a node at design time. It also helps when a node is selected to change the content of the PropertyGrid displayed at design time.

TreeListNodeCollectionConverter & TreeListNodeConverter

Those are the converters for Collection and Node, it allows to change their respective visualizations on the PropertyGrid object. For instance, a node showing its name instead of "TreeListNode1".

TreeListNodeCollectionEditor

This is the collection editor stated above. Allows to use a CollectionEditor from within another CollectionEditor.

TreeListNodePropertyDescriptor

This is the piece that makes Nodes have its little (+) sign at design time Wink | ;)

Points of Interest

I've learned a lot of things writing this component. I know that it is not really finished yet, but I hope that other people will join in to move forward and bring it to a stable state.

Progress

Sample Image

I also wanted to implement a possibility to show a tree being filled without having to wait for a non responsive control. Therefore the property "IsBusy()" of the TreeList can be set to show a progressbar.

VisualStyles

Sample Image

I've also put the option to draw the tree (kind of fantasy) without the Windows XP styles.

Scrollbars

Sample Image

I wanted to have scrollbars if the content of the control was too small to show everything. This was a bit of a question for me. I used the Skybound.VisualStylesProvider to achieve the XP look.

Additional insight

I'll be writing more in-depth about this control later on if I see that people like it.

History

That was my first article guys, hope you enjoyed it Wink | ;)

  • May 06, 2005 - v.0.1.

License

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

Share

About the Author

Nicolas Wälti
Software Developer (Senior)
Switzerland Switzerland
No Biography provided

Comments and Discussions

 
GeneralMy vote of 3 PinmemberSunKwon4-May-12 15:01 
Questionhow I get this application in vc++ Pinmemberjatin dave8-Jan-09 3:29 
GeneralNo more supported PinmemberNick Waelti25-Aug-07 23:20 
Questionneed for vb 2005 Pinmemberpippobuado515-Aug-07 19:43 
GeneralPropertyGrid Question Pinmember@FrankDrebin@31-Jul-07 1:34 
GeneralRe: PropertyGrid Question PinmemberNick Waelti31-Jul-07 1:55 
QuestionAnybody has this working on VS 2005? PinmemberVicmart6913-Mar-07 14:48 
Generaldepth Pinmembernextmove20-Sep-06 10:34 
Roll eyes | :rolleyes: Great control and great code.
 
I have one question. I am using it to make a menu-component for an application. But is it possible to make more then one child-levels. Now when I want to add a child to a child the collection-editor won't open.
 
willem
AnswerRe: depth PinmemberNick Wälti20-Sep-06 19:41 
GeneralRe: depth Pinmembernextmove21-Sep-06 6:21 
Generalparent Property Pinmembermcs@gdiniter.it18-Sep-06 3:01 
GeneralProblem of "first node can be selected " and my Trying to fix PinmemberBNW8-Jul-06 23:18 
QuestionHow can I build the tree from the database using parent and child table Pinmemberxhaileyn30-Dec-05 1:13 
GeneralDynamically added nodes fix PinmemberKuling22-Oct-05 2:11 
GeneralTransparency PinmemberChris Kolkman21-Oct-05 6:06 
GeneralRe: Transparency PinmemberNick Waelti10-Mar-06 3:11 
GeneralRe: Transparency PinmemberChris Kolkman10-Mar-06 3:56 
Generaljust some advice PinsussHuma D Allan30-Aug-05 23:24 
GeneralRe: just some advice PinmemberNick Waelti1-Sep-05 19:22 
QuestionHow to use ProgressBar in TreeList PinmemberDotNET7422-Aug-05 22:11 
AnswerRe: How to use ProgressBar in TreeList PinmemberNick Waelti23-Aug-05 2:00 
GeneralMouseDown problem PinmemberDotNET747-Jul-05 23:46 
GeneralRe: MouseDown problem PinmemberNick Waelti7-Jul-05 23:55 
GeneralDynamically added nodes and scrollbars PinsussAllixria27-Jun-05 13:51 
GeneralRe: Dynamically added nodes and scrollbars PinsussAllixria27-Jun-05 18:01 
GeneralRe: Dynamically added nodes and scrollbars PinmemberKuling22-Oct-05 3:41 
GeneralRe: Dynamically added nodes and scrollbars PinmemberNick Waelti6-Jul-05 22:39 
GeneralMissing nodes Pinmembercarloqueirolo27-Jun-05 4:24 
GeneralRe: Missing nodes PinmemberNick Waelti6-Jul-05 22:43 
GeneralSome issues PinmemberRoger Jakobsson8-Jun-05 5:37 
GeneralRe: Some issues PinmemberNick Waelti10-Jun-05 3:00 
QuestionCan I use it in ASP.NET page? Pinmemberfooks22-May-05 20:03 
AnswerRe: Can I use it in ASP.NET page? PinmemberNick Waelti23-May-05 0:57 
AnswerRe: Can I use it in ASP.NET page? PinmemberGMorris26-May-05 3:49 
GeneralVery nice! PinmemberCrinoid20-May-05 7:18 
GeneralRe: Very nice! PinmemberNick Waelti23-May-05 0:56 
GeneralGreat Job PinmemberBriga19-May-05 4:26 
GeneralRe: Great Job PinmemberNick Waelti23-May-05 0:55 
GeneralGiving gradient fill in the background Pinmemberlflutt17-May-05 13:19 
GeneralRe: Giving gradient fill in the background PinmemberNick Waelti17-May-05 20:31 
GeneralGreat PinmemberMarc Sommer15-May-05 0:22 
GeneralRe: Great PinmemberNick Waelti16-May-05 19:56 
Questiondouble click to collapse? PinmemberUnruled Boy12-May-05 19:16 
AnswerRe: double click to collapse? PinmemberNick Waelti13-May-05 1:15 
Questionmimics the msn 7 animated graphics? PinmemberUnruled Boy12-May-05 19:04 
AnswerRe: mimics the msn 7 animated graphics? PinmemberNick Waelti13-May-05 1:14 
GeneralVery Informative PinmemberIcharus12-May-05 13:19 
GeneralRe: Very Informative PinmemberNick Waelti13-May-05 1:13 
GeneralBackground image PinmemberRizwan Bashir12-May-05 2:08 
GeneralRe: Background image PinmemberNick Waelti13-May-05 1:10 

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
Web03 | 2.8.140921.1 | Last Updated 10 May 2005
Article Copyright 2005 by Nicolas Wälti
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid