简体   繁体   中英

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?

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;

Came here looking for a solution to the same problem but in C++. Ondrej Kelle's answer translated in C++ is like this:

TTreeView* tree;
std::string str;
HWND EditHandle = TreeView_GetEditControl(tree->Handle);
::SendMessage(EditHandle, WM_SETTEXT, 0, (LPARAM)(str.c_str()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM