Tree nodes renaming

2 posts, 0 answers
  1. Itera
    Itera avatar
    5 posts
    Member since:
    Jan 2011

    Posted 11 Apr 2011 Link to this post

    Hello, all

    I want the behavior of Tree nodes renaming same as behavior of renaming files and folders in Windows Explorer:
    When user press F2 or select node and after a few seconds click node text node starts edit mode.
    When user double click on the node I need to open according document. No renaming on node double click.
    Could you help me?

    Best regards,
    Andrew Shyliuk
  2. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 14 Apr 2011 Link to this post

    Hello Itera,

    Your question has already been answered in the other thread you have opened. 

    We kindly ask you to use just one support channel to contact us. Posting the same questions more than once slows down our response time because we will need to review and address two or more tickets instead of one. Moreover, support threads are handled according to license and time of posting, so if it is an urgent issue, we suggest that you use a support ticket, which would be handled before a forum thread.

    I am going to post the answer to your question in this thread too, so other users can benefit from it too:

    "Thank you for this suggestion. We try to keep our API and behavior similar to Microsoft's and that is why I added your suggestion in our issue tracking system. We will consider it when planning our future releases. I updated also your Telerik points accordingly.

    You can implement this behavior by using a custom RadTreeViewElement . Please consider the following sample:"

    Copy Code
    public class MyTreeView : RadTreeView
    {
        protected override RadTreeViewElement CreateTreeViewElement()
        {
            return new MyTreeViewElement();
        }
     
        public override string ThemeClassName
        {
            get return typeof(RadTreeView).FullName; }
            set {}
        }
    }
     
    public class MyTreeViewElement : RadTreeViewElement
    {
        RadTreeNode lastClickedNode;
        Timer timer = new Timer();
     
        public MyTreeViewElement()
        {
            this.AllowEdit = true;
            timer.Interval = SystemInformation.DoubleClickTime + 200;
            timer.Tick += new EventHandler(timer_Tick);
        }
     
        protected override void DisposeManagedResources()
        {
            base.DisposeManagedResources();
            if (timer != null)
            {
                timer.Dispose();
                timer = null;
            }
        }
     
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadTreeViewElement);
            }
        }
     
        protected override bool ProcessMouseDoubleClick(MouseEventArgs e)
        {
            RadTreeNode node = GetNodeAt(e.Location);
            if (node != null)
            {
                lastClickedNode = null;
                MessageBox.Show("Node: " + node.Text + " double clicked!");
                return false;
            }
            return base.ProcessMouseDoubleClick(e);
        }
     
        protected override bool ProcessMouseUp(MouseEventArgs e)
        {
            RadTreeNode node = GetNodeAt(e.Location);
                 
            if (node.Current && node == lastClickedNode)
            {
                timer.Start();
            }
     
            lastClickedNode = node;
     
            this.AllowEdit = false;
            bool result = base.ProcessMouseUp(e);
            this.AllowEdit = true;
     
            return result;
        }
     
        void timer_Tick(object sender, EventArgs e)
        {
            timer.Stop();
            if (lastClickedNode != null && lastClickedNode.Current)
            {
                lastClickedNode = null;
                BeginEdit();
            }
        }
    }


    Thank you for your understanding. 

    Greetings,
    Stefan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top