GetNextItem (Delphi)
Description
This example demonstrates how to retrieve all the selected items in a ListView component and add the Caption of the selected ListItems to a ListBox component. Add a button, a list view, and a list box to the form.
Code
procedure TForm1.Button1Click(Sender: TObject);
var
Item: TListItem;
begin
Item := ListView1.Selected;
while Item <> nil do
begin
ListBox1.Items.Add(Item.Caption);
Item := ListView1.GetNextItem(Item, sdAll, [isSelected]);
end;
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;