TListItemsInsert (Delphi)

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

procedure TForm1.Button1Click(Sender: TObject);
var InsertItem : TListItem;
begin
  with ListView1 do
  begin
    if (Selected = nil) then exit;
    InsertItem := Items.Insert(Selected.Index);
  end;
  InsertItem.Caption := Edit1.Text;
end;

procedure TForm1.FormCreate(Sender: TObject);
var ListItem : TListItem;
begin
  ListView1.ViewStyle := vsList;
  ListItem := ListView1.Items.Add;
  ListItem.Caption := 'Apples';
  ListItem := ListView1.Items.Add;
  ListItem.Caption := 'Oranges';
  ListItem := ListView1.Items.Add;
  ListItem.Caption := 'Pears';
end;

Uses