Click here to Skip to main content
Licence 
First Posted 13 Mar 2004
Views 39,415
Bookmarked 13 times

Using the treeview in your applications

By | 13 Mar 2004 | Article
This article explains how to link instances of classes to your treenodes.

Introduction

In this article I am going to explain how you can link a treenode in a treeview to your underlying model.

I can't see the bush with the trees in front of it

Linking a TreeNode to your document structure in an application is common problem. There's almost always an extensive amount of code needed to map all the treenodes to the appropiate items in your code. Well here comes a simple solution to the problem:

Making a custom TreeNode

first we need to make a new class and inherit the original treenode. The code looks like this:

public class WMIClassNode: TreeNode
{
    public WMIClassNode()
    {
        
    }

    private ManagementObject obj;

    public ManagementObject ManagementObject { get { return obj; } set { obj = value; } }
}

I use this simple class to link a treenode to a ManagementObject in my application. No need for all that difficult code, just use the ManagementObject property of this class to get the ManagementObject associated with this node.

Using the customized TreeNode

You can use this TreeNode just as good as any other TreeNode. You can simple make new instances of the TreeNode and add them to the treeview. The extra property ManagementObject can be used to link this node to a ManagementObject in your application.

Conclusion

I hope this article explains a little how to customize the standard .Net components for your own use.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

WillemM

Web Developer

Netherlands Netherlands

Member

WillemM is a 25 year old software developer working for Info Support. He loves new technology and spends most of his free time finding new ways to do things with his computer.
 
When not working on computers you can find him outside with his camera taking pictures.

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 1 Pinmemberluisxvarg6:49 15 Jul '09  
QuestionWhat about using Tag? PinmemberLorenzoDV12:27 13 Apr '04  
AnswerRe: What about using Tag? PinmemberWillemM20:13 13 Apr '04  
GeneralRe: What about using Tag? PinmemberBaris Kurtlutepe20:46 1 May '04  
QuestionRe: What about using Tag? PinmemberSAKryukov14:36 10 Nov '09  
GeneralSimple good idea Pinmemberbmiller12:03 15 Mar '04  
GeneralRe: Simple good idea PinmemberWillemM20:15 13 Apr '04  
QuestionWhy should this be useful? PinmemberRobert Rohde6:25 14 Mar '04  
AnswerRe: Why should this be useful? Pinmemberleppie11:25 14 Mar '04  
GeneralRe: Why should this be useful? PinmemberWillemM8:36 19 Mar '04  

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
Web02 | 2.5.120517.1 | Last Updated 14 Mar 2004
Article Copyright 2004 by WillemM
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid