I created a CustomTreeNode that derives from TreeNode so I can add extra attributes. To create a TreeView that is composed by my CustomTreeNodes I have also created a CustomTreeView that overrides the TreeNode CreateNode() method to return a new CustomTreeNode.
Basically:
public class CustomTreeNode : TreeNode
{
int type;
public CustomTreeNode() : base()
{}
public void setNodePlageType(int type)
{ this.type = type; }
public int getNodePlageType()
{ return type; }
}
and
public class CustomTreeView : TreeView
{
protected override TreeNode CreateNode()
{
return new CustomTreeNode();
}
}
Everything seems fine when I add the CustomTreeNodes to the CustomTreeView, The debug shows that the CustomTreeView.Nodes[0] has a CustomTreeNode element with my "type" custom property correct.
The problem is when I try to use events associated with the CustomTreeView. I added this event:
TreeView1.SelectedNodeChanged += new EventHandler(NodeExpanded);
but that method receives:
void NodeExpanded(Object sender, EventArgs e)
So I only have access to the selected node by using the property TreeView1.SelectedNode which returns a TreeNode not a CustomTreeNode! So when I try to do something with the selected node I lose my "type" custom property...
Can you help me reformulate my code?
I am doing this in a Sharepoint 2010 WebPart, don't know if it is any useful information...


Sign In
Create Account

Back to top









