Customizing Tree Node
-
I'm building an application and I'm trying to use my own class which adds a bit extra information to a TreeNode. But even though I override ToString() when they are rendered by the TreeView they seem to use the standard TreeNode.ToString(). I'm guessing this is because when the TreeView iterates the Nodes it contains it treats them as TreeNodes. That would make sense. So the question is what is there a way to override TreeNode.ToString() or get the TreeView to treat the objects as MyTreeNodes rather than ordinary ones.
-
I'm building an application and I'm trying to use my own class which adds a bit extra information to a TreeNode. But even though I override ToString() when they are rendered by the TreeView they seem to use the standard TreeNode.ToString(). I'm guessing this is because when the TreeView iterates the Nodes it contains it treats them as TreeNodes. That would make sense. So the question is what is there a way to override TreeNode.ToString() or get the TreeView to treat the objects as MyTreeNodes rather than ordinary ones.
Hi! I guess you'd have to override the
Text
property of TreeNode, not theToString()
method. Regards, mav -- Black holes are the places where god divided by 0... -
I'm building an application and I'm trying to use my own class which adds a bit extra information to a TreeNode. But even though I override ToString() when they are rendered by the TreeView they seem to use the standard TreeNode.ToString(). I'm guessing this is because when the TreeView iterates the Nodes it contains it treats them as TreeNodes. That would make sense. So the question is what is there a way to override TreeNode.ToString() or get the TreeView to treat the objects as MyTreeNodes rather than ordinary ones.
Hi, Mav is right - you need the
Text
property, but it is not declared as virtual so you cannot override it. The displayed text can be set by using one of the constructors that takes a string, or you can set the value of theText
property directly. TheTreeView
just displays this value. ---------------------------- Be excellent to each other :) -
I'm building an application and I'm trying to use my own class which adds a bit extra information to a TreeNode. But even though I override ToString() when they are rendered by the TreeView they seem to use the standard TreeNode.ToString(). I'm guessing this is because when the TreeView iterates the Nodes it contains it treats them as TreeNodes. That would make sense. So the question is what is there a way to override TreeNode.ToString() or get the TreeView to treat the objects as MyTreeNodes rather than ordinary ones.
Thanks guys... Because i need my text to be somewhat dynamic I have done a RefreshText() method which will update the Nodes Text property to what it needs to be. I hoped there was a more elegant solution but it appears not. Just means if I add a node I have to go down the tree and refresh all the nodes.. It seems to work. Thanks for your help I'm still trying to get my head around virtual override new and derivation of classes and stuff.