TStringsMove (C++)

From RAD Studio Code Examples
Jump to: navigation, search


This example uses a list box and a button on a form. The list box contains items when the form appears. When you select an item and click the button, the selected item in the list box is moved to the top of the list box.


__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
  ListBox1->MultiSelect = false;
  Button1->Caption = "Move to Top";
  for (int i = 1; i <= 10; i++)
    ListBox1->Items->Add("Item " + IntToStr(i));

void __fastcall TForm1::Button1Click(TObject *Sender)
  if (ListBox1->ItemIndex >= 0 && ListBox1->ItemIndex <= 9)
	ListBox1->Items->Move(ListBox1->ItemIndex, 0);