This is a migrated thread and some comments may be shown as answers.

Preventing the Edit of Specific Nodes

2 Answers 117 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 26 Mar 2013, 06:07 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 29 Mar 2013, 01:39 PM
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.
0
Paul
Top achievements
Rank 1
answered on 29 Mar 2013, 03:42 PM
Works great, thanks.
Tags
Treeview
Asked by
Paul
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Paul
Top achievements
Rank 1
Share this question
or