Inheriting from the TreeNode class

Discussion in 'ASP .Net Web Controls' started by Alexander Walker, Jan 15, 2006.

  1. Hello

    I have a written a class that inherits from the TreeNode class

    I want to use the inherited TreeNode class to attach custom properties to
    the nodes in a TreeView web control

    I am trying to use the TreeNodePopulate event to read the custom property
    when the user expands a node

    The problem is that the custom node is not recognised when the event fires
    after the page has been rendered

    How can I access the custom node during postbacks, I get the feeling that
    the custom node isn't being created, even though I've overridden the
    CreateNode method, is there something else I should do? Do I need to
    override other methods that persist the custom properties of the custom
    treenode? Am I doing this the wrong way? Should I take an entirely different
    approach?

    Here is some of the code

    public class CustomTreeView : TreeView
    {
    protected override TreeNode CreateNode()
    {
    return new CustomTreeNode();
    }
    }

    public class CustomTreeNode : TreeNode
    {
    private int customInt;

    public int CustomInt
    {
    get
    {
    return customInt;
    }
    set
    {
    customInt= value;
    }
    }

    }


    protected void customTreeView_TreeNodePopulate(object sender,
    TreeNodeEventArgs e)
    {
    CustomTreeNode node = e.Node as CustomTreeNode;
    // node == null
    // i need to access node.CustomInt
    ...
    }

    Thanks

    Alex
    Alexander Walker, Jan 15, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joel Barsotti
    Replies:
    4
    Views:
    2,159
    Joel Barsotti
    Oct 30, 2003
  2. tanya foster
    Replies:
    3
    Views:
    3,697
    tanya foster
    May 18, 2006
  3. Richard Lee
    Replies:
    4
    Views:
    1,019
    James Kanze
    Mar 6, 2008
  4. Replies:
    4
    Views:
    384
  5. Alexander Walker

    Inheriting from the TreeNode class

    Alexander Walker, Jan 15, 2006, in forum: ASP .Net Web Controls
    Replies:
    6
    Views:
    566
    Steven Cheng[MSFT]
    Jan 23, 2006
Loading...

Share This Page