How to put a TreeNode into Edit mode and make the text unselected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TimMackey
    New Member
    • Sep 2010
    • 1

    How to put a TreeNode into Edit mode and make the text unselected

    I have a c# app in which I would like to allow the user to enter new nodes in a TreeView control without having to use the mouse.

    I am able to intercept keystrokes in OnKeyDown, and the following code is working successfully

    Code:
    TreeNode newNode = new TreeNode( e.KeyData.ToString() );
    Nodes.Add(newNode);
    LabelEdit = true;
    newNode.BeginEdit();
    The problem is that the first letter in the node being edited is selected, which causes the following keystroke to replace the selected character. Typing "HELLO" results in "ELLO", unless the user first presses the right-arrow key to deselect the selected first character.

    I tried setting e.Node.IsSelect ed = false in OnBeforeLabelEd it, but cannot because the IsSelected property is read-only.

    How can I programatically deselect the first character and position the edit cursor after the first character?
Working...