Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extend TreeView Class

Status
Not open for further replies.

nunob

Programmer
Nov 9, 2005
4
PT
Hi,

I want my TreeNodes to have extra properties so i've extended the TreeNode Class and add a few new properties, but i need to extend the UltraTree Class so i can add this new nodes instead of the traditional nodes, how can i acomplish this,


thanks
 
cant you inherit from it and then add your extesnions
 
i can inherit.. and then what?

for example the method tree.Nodes.Add accepts TreeNodes but i want it to add MyTreeNodes.
 
MyTreeNodes are TreeNodes.

if Rectangle is the parent, and Square is the child, then you can safely assume that every Square is a rectangle, but not every rectangle is a square. So you can treat any square as if it were a rectangle.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
You'll have to override the Nodes to accept your MyTreeNodes type instead.

If your just adding properties then the inherited TreeView may be able to pick up the originals and draw them itself. However if any of your extra properties should cause it to display differently then you'll have to draw the TreeView parts yourself.
 
To ThatRickGuy: that's just how I feel, but some while ago I was discussing in another thread about this and it is not the way VS thinks. I suggested that every chimpansee is a monkey, so if a method asks for a monkey, I should be able to give it a chimpansee, right? I was corrected though, it doesn't work that way. I can't find the thread anymore though :(

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
Hi Rick

You are right, the thing is that i've tried:

dim aNode as MyTreeNode
aNode = Tree.Nodes.Add(key, text)

and i got an InvalidCastException, and thought it wouldn´t work but then i changed the code to

aNode.Key = key
aNode.Text = text
Tree.Nodes.Add(aNode)

and it worked fine


thanks

 
nunob, just remember that when you pull a node out of the tree now you'll have to cast it to your new custom node type. And do so carefully as it is possible that you have pulled out a node that is note one of your new nodes.

Ruffnekk, I think I remember that thread. But I'm pretty sure the issue being debated there was not if every square was a rectangle, but could a rectangle be treated like a square.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Maybe I'm still confused about it and that might exactly be the point I wasn't getting ;)

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top