User260076833 posted
Hello,
I need to subclass TreeNode to extend it with new attributes and use it in a custom control.
public class MyTreeNode : TreeNode
{
public String type { get; set; }
}
I add them to a TreeView like this:
public class TreePageView : CompositeControl
{
TreeView trv;
...
protected override void CreateChildControls()
{
...
trv.Nodes.Clear();
MyTreeNode t = new MyTreeNode();
t.myAttribute = "XXX";
trv.Nodes.Add(t);
}
}
I can verify in debug mode that the trv.Nodes collection contains an instance of the class MyTreeNode.
However, in the SelectedNodeChanged event we have another situation:
protected void tvw_SelectedNodeChanged(object snd, EventArgs evt)
{
if (!(trv.SelectedNode is MyTreeNode))
return;
... // never reached
}
Allthough I only add subclassed tree nodes (instances of class MyTreeNode) to the TreeView, the selected node only is an instance of the TreeNode class, but not of the MyTreeNode class.
But in the SelectedNodeChanged event I need access to the originally added node which is an instance of MyTreeNode.
How can I solve that?
Thanks
Magnus