Preventing the Edit of Specific Nodes

3 posts, 1 answers
  1. Paul
    Paul avatar
    23 posts
    Member since:
    Feb 2013

    Posted 26 Mar 2013 Link to this post

    I am trying to prevent the editing of a certain node with this event handler:

    private void radTreeView_Editing(object sender, TreeNodeEditingEventArgs e)
    {
        if (e.Node.Text == "abc")
        {
            e.Node.CancelEdit();
        }
    }

    It appears that I am missing something because the node text is still editable and this exception is thrown:

    System.NullReferenceException: Object reference not set to an instance of an object.
       at Telerik.WinControls.UI.RadTreeViewElement.BeginEdit()
       at Telerik.WinControls.UI.RadTreeViewElement.mouseUpTimer_Tick(Object sender, EventArgs e)
       at System.Windows.Forms.Timer.OnTick(EventArgs e)
       at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    Any suggestions?
  2. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 29 Mar 2013 Link to this post

    Hi Paul,

    Thank you for writing.

    You can use the Cancel property of the event arguments to cancel the editing operation:
    void radTreeView1_Editing(object sender, TreeNodeEditingEventArgs e)
    {
        if (e.Node.Text == "Node2")
        {
            e.Cancel = true;
        }
    }

    I hope this helps.
     

    All the best,
    Stefan
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Paul
    Paul avatar
    23 posts
    Member since:
    Feb 2013

    Posted 29 Mar 2013 Link to this post

    Works great, thanks.
Back to Top