EditText (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example is an event handler for a pop-up menu item. The handler enables the 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.

Code

void __fastcall TForm1::EditItem1Click(TObject *Sender)
{
  TreeView1->Selected->EditText();
}

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  TTreeNode *Node1;
  TreeView1->Items->Clear(); // Remove any existing nodes.
  // Add a root node.
  TreeView1->Items->Add(NULL, "RootNode1");

  /* Set MyTreeNode to the first node in the 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);
}

Uses

Personal tools
Assistance