We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

TreeNodeAdv name property

Hi, I want to replace TreeView with TreeViewAdv and I need the TreeNodeAdv "name" property.

But I get an error

Error    CS1061    'TreeNodeAdv' does not contain a definition for 'Name' and no extension method 'Name' accepting a first argument of type 'TreeNodeAdv' could be found (are you missing a using directive or an assembly reference?)  

Can I solve it somehow?


3 Replies

KR Kannan R Syncfusion Team October 9, 2017 09:16 AM UTC

  
Hi Mate 
 
Thank you for using Syncfusion support.  
 
Yes, TreeNodeAdv does not have Name property and it can be achieved by creating custom control inherited from TreeNodeAdv. Please make use of code snippets in below.  
 
Code Snippet: [C#] 
 
 
        public class TreeNodeAdvExt : TreeNodeAdv 
        { 
        public TreeNodeAdvExt() 
        { 
 
        } 
 
        /// <summary> 
        /// Holds the Node name 
        /// </summary> 
        private string m_Name = string.Empty; 
        /// <summary> 
        /// Gets/Sets the Node name 
        /// </summary> 
        public string Name 
        { 
            get { return m_Name; } 
            set { m_Name = value; } 
        } 
 
        } 
 
            private void TreeViewAdv1_MouseUp(object sender, MouseEventArgs e) 
        { 
            if (this.treeViewAdv1.GetNodeAtPoint(e.Location) != null && this.treeViewAdv1.GetNodeAtPoint(e.Location) is TreeNodeAdvExt) 
                MessageBox.Show("Node Name is:  " + (this.treeViewAdv1.GetNodeAtPoint(e.Location) as TreeNodeAdvExt).Name.ToString()); 
        } 
 
        private void Form1_Load(object sender, EventArgs e) 
        { 
            treeNodeAdvExt1.Name = "Node 0"; 
            treeNodeAdvExt2.Name = "Node 1"; 
            treeNodeA3vExt3.Name = "Node 2"; 
            treeNodeAdvExt4.Name = "Node 3"; 
            treeNodeAdvExt5.Name = "Node 4"; 
            treeNodeAdvExt6.Name = "Node 5"; 
            treeNodeAdvExt7.Name = "Node 6"; 
        } 
 
                  
 
 
 
Kindly check with above solution and let us know if it helps. 
 
Regards 
Kannan 



VH Vhalaky October 9, 2017 02:04 PM UTC

Hi, thank you for your fast answer!

It is working good but I have another problem:

TreeNodeAdvExt cnode = new TreeNodeAdvExt();
cnode.Text = "xxxxx";
cnode.Name = "cnode1";

//it is ok
treeNodeAdvExt1.Nodes[0].Nodes.Add(cnode);

//but it is not working - obviously. Regular TreeView supports this.
treeNodeAdvExt1.Nodes["Node 4"].Nodes.Add(cnode);

I can search by name but I have large trees (100 000+ nodes, including a multicolumn). I think search won't be too efficient.



KR Kannan R Syncfusion Team October 10, 2017 09:51 AM UTC

Hi Mate   
   
Thank you for your update.   
   
Yes, there is no default option at present to search TreeNodeAdv using its Name. We can only pass index in Nodes collection and not the TreeNodeAdv name. So we have prepared work around by performing search in Iteration process to help you on this and it will work for all levels of nodes, not just the Initial level. Please make use of below code example.   
 
Code example: [C#]   
   
   
        TreeNodeAdv node = GetNodeByName(this.treeViewAdv1.Nodes, this.nodeNameCmb.SelectedItem.ToString());   
   
        /// <summary>   
        /// Gets the TreeNodeAdv name   
        /// </summary>   
        /// <param name="nodes">Node Collection</param>   
        /// <param name="Name">Node Name</param>   
        /// <returns>TreeNodeAdv</returns>   
        public static TreeNodeAdv GetNodeByName(TreeNodeAdvCollection nodes, string Name)   
        {   
            TreeNodeAdv matchNode = null;   
            bool isMatchFound = false;   
   
            foreach (object node in nodes)   
            {   
                if (node is TreeNodeAdvExt && (node as TreeNodeAdvExt).Name == Name)   
                {   
                    isMatchFound = true;   
                    matchNode = node as TreeNodeAdv;   
                    return matchNode;   
                }   
   
                if (!isMatchFound)   
                {   
                    matchNode = GetNodeByName((node as TreeNodeAdvExt).Nodes, Name);   
                    if (matchNode != null)   
                    {   
                        return matchNode;   
                    }   
                }   
            }   
            return null;   
        }   
   
 
   
 
Note: Since it is needed to validate in all node levels, it will consume required timeline for this iteration process. 
   
Kindly check with above solution and let us know if it helps.    
   
Regards   
Kannan   
 


Loader.
Live Chat Icon For mobile
Up arrow icon