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.
Unfortunately, activation email could not send to your email. Please try again.

TreeNodeAdv name property

Thread ID:

Created:

Updated:

Platform:

Replies:

133075 Oct 8,2017 04:43 AM Oct 10,2017 05:51 AM Windows Forms 3
loading
Tags: TreeViewAdv
Vhalaky
Asked On October 8, 2017 04:43 AM

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?


Kannan R [Syncfusion]
Replied On October 9, 2017 05:16 AM

  
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 


Vhalaky
Replied On October 9, 2017 10:04 AM

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.


Kannan R [Syncfusion]
Replied On October 10, 2017 05:51 AM

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   
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;