none
Canceling TreeNode editing on TreeView Control RRS feed

  • Question

  • Is it possible to have the user begin to edit a TreeNode label and then cancel their changes by hitting escape? That is the default behavior in Windows Explorer, but I can't seem to get it to work with .NET TreeView.

     

    I've tried handling the AfterLabelEdit event, but can't see how to determine if the event was called because the escape key was hit rather than enter or a mouse click outside the edit box. I thought perhaps the CancelEdit property might be set, but this doesn't appear to be the case.

     

    Any ideas how I can get this behavior? Seems like it ought to be a common thing to do...

     

    Cheers,

     

    Simon

     

    Wednesday, May 9, 2007 10:11 PM

Answers

All replies

  • Not quite sure what you are looking for.  Yes, AfterLabelEdit fires when the user presses Escape.  That wouldn't be any different though from the user just typing the same label.  Try something like this:

        private string mCurrentLabel;
        private void treeView1_BeforeLabelEdit(object sender, NodeLabelEditEventArgs e) {
          mCurrentLabel = e.Label;
        }
        private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) {
          if (e.Label != mCurrentLabel) Console.WriteLine("Yes, something changed");
        }

    Wednesday, May 9, 2007 10:22 PM
    Moderator
  • Basically what I want is the same behavior as windows explorer: if you begin to edit a node label, change some characters, and then hit escape, then the node text reverts back to what it was before you started editing.

     

    This is also what happens if you set CancelEdit = true in the AfterLabelEdit handler (stangely, EndEdit(true) isn't enough). But, from within the AfterLabelEdit handler there seems to be no obvious way to tell whether the user terminated editing by pressing escape or not, and hence no way to know if CancelEdit should be set to true.

     

    Any ideas?

     

    Cheers,

     

    Simon

     

    Wednesday, May 9, 2007 10:55 PM
  • Again, not quite sure what you're talking about.  Pressing Escape definitely cancels editing of the node when I try it.  Detecting it ought to work with the code I provided.  What exact requirement are you looking for?
    Wednesday, May 9, 2007 11:03 PM
    Moderator
  • Hi,

          I am using ASP TreeView control in my application and binding through the database table.

    I want to know whether there is any facility to edit the leaf nodes on double click.

    I don't want to provide another window to edit the items in the treeview,

    Pls let me know whether it is possible or not and if it is possible then how can I achieve this?

     

    Waiting for your reply...

     

    Thanks & Regards,

     Suresh Talasta.

    suresh.talasta@gmail.com

    Monday, May 14, 2007 5:09 AM
  •  SureshTalasta wrote:

    Hi,

          I am using ASP TreeView control in my application and binding through the database table.

    I want to know whether there is any facility to edit the leaf nodes on double click.

    I don't want to provide another window to edit the items in the treeview,

    Pls let me know whether it is possible or not and if it is possible then how can I achieve this?

     

    Waiting for your reply...

     

    Thanks & Regards,

     Suresh Talasta.

    suresh.talasta@gmail.com



    For ASP.NET questions, we have http://forums.asp.net, I recommend you post ASP.NET questions there for better reponses.
    Wednesday, May 16, 2007 3:38 AM
  • Yes, the ESC key ought to work.
    Wednesday, May 16, 2007 3:39 AM