Search code examples
delphitreevieweditordelphi-xetreeviewitem

TTreeView: How to change the text of item's inplace editor?


I have a TreeView with editable items. When I press F2 or click any item after selection, the inplace editor appearing.

How can I change the text which is displayed in that editor before showing it? For example, my tree item's text is Point 1 (300, 450), but I want my inplace editor to display only Point 1.

I tried to catch OnEditing event like that:

procedure TForm1.TreeViewEditing(Sender: TObject; Node: TTreeNode; 
  var AllowEdit: Boolean);
begin
  AllowEdit := True;
  Node.Text := 'text to edit';
end;

However, the text of inplace editor isn't changing, the tree item's text updated only after cancelling edit. How to do this correctly?


Solution

  • Try if the following suits you:

    uses
      Winapi.CommCtrl;
    
    procedure TForm1.TreeView1Editing(Sender: TObject; Node: TTreeNode; var AllowEdit: Boolean);
    var
      EditHandle: THandle;
      S: string;
    begin
      AllowEdit := True;
      S := 'text to edit';
      EditHandle := TreeView_GetEditControl((Sender as TTreeView).Handle);
      SendMessage(EditHandle, WM_SETTEXT, 0, LParam(PChar(S)));
    end;