none
In TreeView treenode BeginEdit() is not working RRS feed

  • Question




  • In C# I have used TreeView in my Form.

    In TreeNode editing I have used validation so that if user enter
    illegal characters and press enter, Error message is shown to user.

    But when user press Ok in messagebox, TreeNode doesn't return to edit
    mode even I call TreeNode.BeginEdit(). However it is working fine in
    ListView. I dont want to override TreeView. Please any suggestion with
    code. API method is also welcomed.
    Wednesday, December 3, 2008 5:41 AM

Answers

  • Hi prpradip,

     

    You can handle the AfterLabelEdit event to set “e.CancelEdit = true;”, the invalid value will be rollback to the previous (correct) one.

     

    Sincerely,

    Kira Qian

    Thursday, December 4, 2008 9:38 AM
  • TreeView doesn't like it much when you change focus or do something modal in one of its events.  You can work around it by delaying the action until the event processing is completed.  For example:

        private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) {
          e.CancelEdit = true;
          this.BeginInvoke(new MethodInvoker(ShowAMessage));
        }

        private void ShowAMessage() {
          MessageBox.Show("No can do");
          treeView1.SelectedNode.BeginEdit();
        }

    Thursday, December 4, 2008 2:10 PM
    Moderator

All replies

  • Hi prpradip,

     

    You can handle the AfterLabelEdit event to set “e.CancelEdit = true;”, the invalid value will be rollback to the previous (correct) one.

     

    Sincerely,

    Kira Qian

    Thursday, December 4, 2008 9:38 AM
  • TreeView doesn't like it much when you change focus or do something modal in one of its events.  You can work around it by delaying the action until the event processing is completed.  For example:

        private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) {
          e.CancelEdit = true;
          this.BeginInvoke(new MethodInvoker(ShowAMessage));
        }

        private void ShowAMessage() {
          MessageBox.Show("No can do");
          treeView1.SelectedNode.BeginEdit();
        }

    Thursday, December 4, 2008 2:10 PM
    Moderator