TopIndex (C++)

From RAD Studio Code Examples
Jump to: navigation, search


The following example uses a list box containing a list of strings, a button, and an edit box on a form. When you run the application and click the button, the third item in the list becomes the first item and the index value of that item appears in the edit box. The index value displayed is 2, indicating the third item in the list (the first item in the list has an index value of 0.)


void __fastcall TForm1::Button1Click(TObject *Sender)
  ListBox1->TopIndex = 2;
  Edit1->Text = IntToStr(ListBox1->TopIndex);

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
  for (int Number = 1; Number <= 20; Number++)
    ListBox1->Items->Add("Item " + IntToStr(Number));