locked
Custom TreeView and Custom TreeNodes RRS feed

  • Question

  • User-1151753060 posted

    Hi,


    I have created two custom tree nodes, one for a parent and one for a child. I've created two custom nodes as I need to render a different set of buttons beside each node. I have also created a custom TreeView and have attempted to override the CreateNode method. However I' not sure how to implement the CreateNode method. The following code snippet illustrates what I'm trying to accomplish.

     
    protected override TreeNode CreateNode()
    {
        if(someCondition)
        {
           return new ParentNode();
        }
        else if(someOtherCondition)
        {
            return new ChildNode();
        }
        else
        {
            return new TreeNode();
        }
    }
     

     
    Tuesday, March 18, 2008 6:21 PM

All replies

  • User-1136466523 posted

    Hi,

    The CreateNode method is a helper method that returns a new instance of the TreeNode class.

    The CreateNode method is used primarily by control developers. Control developers that want to extend the TreeView class by extending the TreeNode class should override this method to return an object that derives from the TreeNode. A common reason to extend the TreeNode class is to override the RenderPreText and RenderPostText methods.

    For more information, see:
    http://msdn.microsoft.com/en-us/library/ms156565.aspx
    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.createnode.aspx

    Thanks.

    Wednesday, March 19, 2008 10:40 PM
  • User-1151753060 posted

    Thanks for your replay,

     
    However this is info I already knew. The reason I derived two different classes from TreeNode was precisely to override RenderPostText in two unique ways. I want the parent node to have a button to create a new child and delete itself and I want child nodes to have buttons such as delete, manage etc. I have also extended the TreeView control and I was attempting to override the CreateNode method. But to do this I would like to have logic in the CreateNode method that decides which type of TreeNode to return i.e. new ChildNode() or new ParentNode(), is this possible?

    Saturday, March 22, 2008 10:50 AM
  • User-1030864281 posted

    I have the same issue,

    Did you find the solution?

    Friday, June 5, 2009 9:11 AM