I've tried unsuccessfully to get a UltraTreeNode to stay in edit mode (of the node label itself), after a user makes an edit.
What I've tried is to use the AfterLabelEdit event to check whether the node's name is acceptable via some routine and if not to try and keep the label in edit mode. I've tried calling PerformAction(UltraTreeAction.EnterEditMode, false, false) from within the AfterLabelEdit handler, but this doesn't seem to work.
Any ideas?
Handle the BeforeLabelEdit event and set the Cancel property of the event arguments to true.
Brian - Thanks, although I don't think that's what I'm looking for.
Basically I am allowing the user to add a node to the three. As soon as the node is added I put it into edit mode, so the user can immediately rename it. It's only after the user types in a new name for the node label, that I want to verify it and if it fails my verification, display a message box to that effect and keep the node label in edit mode.
Unless I am misstaken, this needs to occur in the AfterLabelEdit event, since I want to check the label text after it's been entered. Is there a way in this AfterLabelEdit event to tell the node to stay in label edit mode?
Use the ValidateLabelEdit event.
this.ultraTree1.Override.Editor = new EditorWithText();this.ultraTree1.EditorResolved.BeforeExitEditMode += new BeforeExitEditModeEventHandler(EditorResolved_BeforeExitEditMode);
private void EditorResolved_BeforeExitEditMode(object sender, BeforeExitEditModeEventArgs e){ EmbeddableEditorBase editor = sender as EmbeddableEditorBase;
if ( editor != null ) { if ( string.Equals(editor.CurrentEditText, "foo") == false ) { MessageBox.Show( "Invalid" ); e.Cancel = true; } }}
If you add a node, don't type anything into it and press return, the event does not fire.
Perhaps I am not understanding your request. Please clarify why the following approach does not solve the problem:
private void ultraTree1_ValidateLabelEdit(object sender, ValidateLabelEditEventArgs e){ if ( string.Equals(e.LabelEditText, "foo") == false ) { MessageBox.Show( "Invalid" ); e.StayInEditMode = true; }}
Hi,
after much scratching of head, it appears that this event doesn't get fired unless the user pressed a key, now in normal circumstances, that's ok, as we can supply a sensible default. The problem which is causing an issue, is that there is a possibility that an error could occur when the default text is used (failure to save data to server etc) the result of which I would like to be able to raise a message and force the node back into edit mode, is there any way to acheive that?
Thanks,
Chris