[Editing TTreeNodeShape] 'Return' key to validate a new name

TeeTree VCL for Borland Delphi and C++ Builder.
Post Reply
bertrod
Advanced
Posts: 151
Joined: Wed Sep 07, 2005 4:00 am

[Editing TTreeNodeShape] 'Return' key to validate a new name

Post by bertrod » Fri Feb 17, 2006 11:30 am

Hello,

I think the actual way of beeing able to put a 'Line Return' in the name of a TTreeNodeShape is not very intuitive.

As a I user, I would think that pressing the 'Return' key while editing the name of a TTreeNodeShape will validate the new name, which is not the case.

Is there a way to intercept the 'Return' key to force stopEditing ? I tried to use the 'onKeyPress' event of the TreeView, but this event isn't called when editing a TTreeNodeShape.

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Post by tom » Tue Feb 21, 2006 10:23 am

Hi bertrod,

There are cases in which people want to have full text inside a node (including return characters). It just depends on the functionality of the application.

When in 'text' editing mode, the OnKeyPress event of the tree isn't used, since the focus is on the internal memo of the tree.

Off course you can still intercept the 'return' key, see code below

Code: Select all

procedure TForm2.Tree1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    Key := #0;
    Tree1.StopEditing;
  end;
end;

procedure TForm2.Tree1StartEditing(Shape: TTreeNodeShape;
  var AllowEditing: Boolean);
begin
  if Assigned(Tree1.TextEditor.Memo) then
  begin
    //Tree1.TextEditor.Memo.WantReturns := False;
    Tree1.TextEditor.Memo.OnKeyPress := Tree1KeyPress;
  end;
end;

procedure TForm2.FormDestroy(Sender: TObject);
begin
  if Assigned(Tree1.TextEditor.Memo) then
   Tree1.TextEditor.Memo.OnKeyPress := nil;
end;
You need to assign the keypress event in the OnStartEditing event, since the memo will not be created at first (only at the first use of it)

You can also disable the use of a return key (see commented code concerning WantReturns property of the internal memo. For more information on this, I refer you to the standard delphi helpfile concerning TMemo)

Best regards,
Tom.

bertrod
Advanced
Posts: 151
Joined: Wed Sep 07, 2005 4:00 am

Post by bertrod » Wed Feb 22, 2006 9:27 am

Thanks a lot ! :D

Post Reply