TListItemsInsert (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following example inserts a list item before the selected item in the list view. Place a TButton, a TEdit, and a TListView on the form.

Code

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TListItem *InsertItem;
  if (ListView1->Selected == NULL) return;
  InsertItem =
	ListView1->Items->Insert(ListView1->Selected->Index);
  InsertItem->Caption = Edit1->Text;
}

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  TListItem *ListItem;
  ListView1->ViewStyle = vsList;
  ListItem = ListView1->Items->Add();
  ListItem->Caption = "Apples";
  ListItem = ListView1->Items->Add();
  ListItem->Caption = "Oranges";
  ListItem = ListView1->Items->Add();
  ListItem->Caption = "Pears";
}

Uses