I am trying to inherit from TreeNode to add own nodes to TreeView:
class TreeViewItem : TreeNode
{
public new string Text;
public override string ToString()
{
return "asd";
}
}
I tried that:
TreeViewItem tvi = new TreeViewItem();
tvi.Text = "asd";
trv_bd_content.Nodes.Add(tvi);
But still getting empty node added to TreeView (node without Text “asd”).
What should i do?
As I understand you are going to override
TreeNodejust to display some text you build your own.If values needed for calculation are known before adding the node to tree I would suggest to do it this way:
Overriding a visual element just to keep additional data in it is not a good idea. Usisally you override visual element to modify it’s drawing or something related to it’s behavior as visual element.
For keeping corresponding data you could use
Tagproperty where you can save any data (untyped). So you can put an instance of a class containing your data.