RAD Studio VCL Reference
|
Allows editing a tree node.
function EditText: Boolean;
__fastcall Boolean EditText();
Call EditText to allow a user to edit tree node label text.
C++ Examples:
/* This example is an event handler for a popup menu item. The handler enables editing of the current item in a TListView control. The example would also work with a TTreeView control, or with any instance of a control class derived from TCustomViewControl. */ void __fastcall TForm1::EditItem1Click(TObject *Sender) { TreeView1->Selected->EditText(); } void __fastcall TForm1::FormCreate(TObject *Sender) { TTreeNode *Node1; TreeView1->Items->Clear(); // remove any existing nodes // Add a root node TreeView1->Items->Add(NULL, "RootNode1"); /* Set MyTreeNode to first node in tree view and add a child node to it */ Node1 = TreeView1->Items->Item[0]; TreeView1->Items->AddChild(Node1,"ChildNode1"); // Add another root node TreeView1->Items->Add(Node1, "RootNode2"); /* Reset Node1 to RootNode2 and add a child node to it */ Node1 = TreeView1->Items->Item[2]; TreeView1->Items->AddChild(Node1,"ChildNode2"); /* Reset Node1 to ChildNode2 and add a child node to it */ Node1 = TreeView1->Items->Item[3]; TreeView1->Items->AddChild(Node1,"ChildNode2a"); /* Add another child to ChildNode2 following ChildNode2a */ TreeView1->Items->AddChild(Node1,"ChildNode2b"); // add another root node TreeView1->Items->Add(TreeView1->Items->Item[0], "RootTreeNode3"); } void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { PopupMenu1->Popup(Left + X, Top + Y); }
Delphi Examples:
{ This example is an event handler for a popup menu item. The handler enables editing of the current item in a TListView control. The example would also work with a TTreeView control, or with any instance of a control class derived from TCustomViewControl. } procedure TForm1.EditItem1Click(Sender: TObject); begin TreeView1.Selected.EditText; end; procedure TForm1.FormCreate(Sender: TObject); var MyTreeNode1, MyTreeNode2: TTreeNode; begin with TreeView1.Items do begin Clear; { remove any existing nodes } MyTreeNode1 := Add(nil, 'RootTreeNode1'); { Add a root node } { Add a child node to the node just added } AddChild(MyTreeNode1,'ChildNode1'); {Add another root node} MyTreeNode2 := Add(MyTreeNode1, 'RootTreeNode2'); {Give MyTreeNode2 to a child } AddChild(MyTreeNode2,'ChildNode2'); {Change MyTreeNode2 to ChildNode2 } { and add a child node to it} MyTreeNode2 := TreeView1.Items[3]; AddChild(MyTreeNode2,'ChildNode2a'); {Add another child to ChildNode2, after ChildNode2a } AddChild(MyTreeNode2,'ChildNode2b'); {add another root node} Add(MyTreeNode1, 'RootTreeNode3'); end; end; procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin PopupMenu1.Popup(Left + X, Top + Y); end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|