Results 1 to 4 of 4

Thread: Question on inheritance and component classes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    Question on inheritance and component classes

    I was thinking about inheritance and inheriting from a treenode. Is it possible to create a new class, inherit all from a treenode, and then use the new class to insert a node into a treeview? If so, how would I go about this?

    The main reason I want to do this is for more .Tag properties.


    Thanks!!
    Currently Using: VS 2005 Professional

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Question on inheritance and component classes

    Taco, I use .NET 2003, but I don't think a ton has changed in this area..

    You can use a custom treenode, but you will need to directcast it as the custom class at some points, or you can create a custom class that will sit in the tag of a regular tree node (as a tag is of type object and can hold any .net object)

    here is an example. Its in 2003, but 2005 should be able to open it fine.
    Attached Files Attached Files

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    Re: Question on inheritance and component classes

    Ahha, now I see where you need directcast. I have never used that before. Ok, I have tried to add a new node of type treenodeplus to my treeview but it tells me I cannot because of wrong type. I tried ctype once but nothing. If I used directcast on the treenodeplus node to add it into the treeview would that work?
    Currently Using: VS 2005 Professional

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Question on inheritance and component classes

    If your TreeNodePlus class inherits the TreeNode class then there is no reason that you should not be able to add it to a TreeView. You have to add a TreeNode to a TreeView's Nodes property and a TreeNodePlus object IS a TreeNode. You should only have to cast the object when you RETRIEVE it from the TreeView because it will be returned as a TreeNode reference. As an example, assume you go to a recruitment company who place programmers. They can place you because you are a VB.NET programmer, which inherits programmer. When someone gets you from the recruitment company they are getting a programmer, so they would need to tell everyone that you are a VB.NET programmer so that people would know that they could use your VB.NET skills.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width