Force TreeViewAdv node to stay in edit mode

How can I force a tree node to stay in edit mode? After I add a new node to a tree, I invoke TreeViewAdv.BeginEdit(MyNewNode) to force the user to type in a new name for the node. I also use the NodeEditorValidating event handler to ensure that the name is unique. My event handler looks like this: if (NewNameIsNotUnique(e.Label)) { MessageBox.Show(“Name is not unique”); TreeViewAdv.BeginEdit(e.Node); } What I’m trying to do is to leave the node in editing mode until the user enters a unique name. But instead, when the event handler exits, the node leaves editing mode. This can leave a non-unique node name (which is bad for me). The BeginEdit method doesn’t seem to have any effect. The node is no longer in edit mode when this function completes. If I invoke TreeViewAdv.EndEdit(false) before calling BeginEdit (or instead of calling BeginEdit), then the NodeEditorValidating function is reinvoked in an infinite loop. Any ideas on how to keep the user from leaving a node that’s in edit mode until they’ve entered a valid (in my case, that means unique) node name?

2 Replies

DT Deepa TS Syncfusion Team December 22, 2005 09:30 AM UTC

Hi Jzucker, Please refer to the sample attached with this, that shows how you could accomplish the above by handling the TreeViewAdv''s NodeEditorValidating eventas shown below : private void treeViewAdv1_NodeEditorValidating_1(object sender, Syncfusion.Windows.Forms.Tools.TreeNodeAdvCancelableEditEventArgs e) { if(e.Label=="Syncfusion") { e.Cancel = false; MessageBox.Show("Unique"); e.ContinueEditing = false; } else { // Cancel the label edit action, inform the user, and place the node in edit mode again. // e.Cancel = true; MessageBox.Show("Name is not unique"); // To end editing mode, do this: e.ContinueEditing = true; } } Let me know if this meets your requirements. Thanks for your continued interest in Syncfusion products. Regards, Deepa.T.S

test13.zip


JZ Jon Zucker December 22, 2005 02:31 PM UTC

Well, it sort of works. When I run the sample code in the sample project you provided, it works perfectly. But when I use the same code in my own project, I still get stuck in an infinite loop. The tree''s NodeEditorValidating event is fired again after I exit the event handler, but I don''t know why. I''m still looking into that. Thanks for your help.

Loader.
Up arrow icon