Question

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?

Was it helpful?

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;

OTHER TIPS

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()));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top