GetNextItem (C++)
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
__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";
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TItemStates selected = TItemStates() << isSelected;
TListItem *Item = ListView1->Selected;
while (Item){
ListBox1->Items->Add(Item->Caption);
Item = ListView1->GetNextItem(Item, sdAll, selected);
}
}