Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a TreeView (using Crownwood.DotNetMagic, it should be similar to WinForms) and when the user edits a node, he should not be allowed to leave the edit mode when the text is empty.

The TreeView has similar events like this treeview from WinForms

What I have tried:

I've tried doing this in my AfterLabelEdit but it doesn't exactly do what I want: It sets the text back to the original text but I want it to stay empty in the edit mode (the user should just not be allowed to commit his changes)
C#
if (String.IsNullOrEmpty(e.Label))
{
    e.Cancel = true;
    e.Node.BeginEdit();
    return;
}
Posted
Updated 24-Jul-18 2:18am
v3

1 solution

Create an "add node", delete and a "rename / replace" node function via a PF Key, button etc, and prompt for the required data to apply to the tree view / node.

Your life will be simpler if you maintain "control" of the tree view maintenance process instead of guessing what the user might be trying to do after they've made a move.
 
Share this answer
 
Comments
[no name] 24-Jul-18 5:35am    
So you mean the user shouldn't be able to edit the node by double-clicking it? He should only be able to do it by pressing an extra edit button, right?

This would solve my solution but the program should be more userfriendly and it's faster to double click the node than clicking on it once and then clicking on the Edit button (which also already exists btw).


But thank you for your possible solution. It would be great if you can come up with another idea :)
[no name] 25-Jul-18 15:45pm    
You have to select a node anyway; unless the tree is empty; in which case, how does the user "add"?.

When you select, you can right click and pop up a context menu; seems "friendly" enough compared to wondering what to do with an "invalid" node. No changes to the "view".
[no name] 26-Jul-18 2:11am    
Yeah, that's what I did…. Not quite what I wanted to have but it's fine. Thank you for your Reply!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900