custom TreeNode and SelectNodeChanged
        Posted  
        
            by gilloux
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by gilloux
        
        
        
        Published on 2009-05-07T10:39:25Z
        Indexed on 
            2010/03/22
            11:11 UTC
        
        
        Read the original article
        Hit count: 343
        
Hello,
I'm working on asp.net
I've written a custom Treenode (customTreeNode) that I use to populate a treeview
the problem comes up when firing the selectnodechanged event
this event give me a TreeNode object and not a customTreeNode
and I cannot seem to cast it somehow,
does sy have a clue ?
Thx
here is the code I have
populate my tree
 node.ChildNodes.Add
                (
                    customTreeNode = new customTreeNode(site)
                );
customTreeNode
public class customTreeNode : TreeNode
    {
       public Guid Id { get; set; }
        private SPWebEntry _dataContext;
        public SPWebEntry DataContext
        {
            get
            {
                return _dataContext;
            }
        }
        public customTreeNode(SPWebEntry DataContext)
        {
            _dataContext = DataContext;
            this.Text = _dataContext.Title;
            this.Id = _dataContext.Id;
        }
}
and the event
 void treeViewSiteCollection_SelectedNodeChanged(object sender, EventArgs e)
        {
            treeViewSiteCollection.SelectedNode;
        }
treeViewSiteCollection.SelectedNode is of type TreeNode and I cannot cast it.
Thx guys
© Stack Overflow or respective owner