Treeview Adding a node using begin edit

2 posts, 0 answers
  1. Harshvardhan
    Harshvardhan avatar
    4 posts
    Member since:
    May 2012

    Posted 07 May 2012 Link to this post

    I have a functionality where i need to add nodes to the tree and get the name of the node form the user , in the node by using beginedit.
    I have some custom validation that  i need to do , i am using the valueValidation event for doing that. once the validation is done , If the validation fails , i.e when i do e.cancel = true and validation error gets triggered , i want the new node added during the process to be removed. I tried doing it in validationerror event , but this is not allowed. please let me know how can i do this.

  2. Julian Benkov
    Julian Benkov avatar
    1135 posts

    Posted 10 May 2012 Link to this post

    Hello Harshvardhan,

    Thank you for writing.

    You can use the combination of the Edited and the ValueValidting events to handle this behavior. Here is a sample application demonstrating this approach:
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
    namespace Lab.Tree
        public partial class TreeEditorValidating : MainForm
            private RadTreeView treeView = new RadTreeView();
            public TreeEditorValidating()
                treeView.Dock = DockStyle.Fill;
                treeView.Parent = this;
                treeView.AllowEdit = true;
                treeView.ValueValidating += treeView_ValueValidating;
                treeView.Edited += treeView_Edited;
            bool removeLast = false;
            void treeView_Edited(object sender, TreeNodeEditedEventArgs e)
                if (removeLast)
                removeLast = false;
            void treeView_ValueValidating(object sender, TreeNodeValidatingEventArgs e)
                if (removeLast)
                if (e.NewValue.ToString() != "MyValue")
                    removeLast = true;
                    e.Cancel = true;
            protected override void OnButton1Click()
                RadTreeNode node = treeView.Nodes.Add("new node");

    I hope this helps.

    Julian Benkov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top