RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomListBox.TopIndex Property

Specifies the index number of the item that appears at the top of the list box.

Pascal
property TopIndex: Integer;
C++
__property int TopIndex;

Use TopIndex property to find or set the first item displayed at the top of the list box. TopIndex can be used, for example, to change the topmost item to a different item in the list.  

C++ Examples: 

 

/*
The following example uses a list box containing a list of
strings, a button, and an edit box on a form. When the user
runs the application and clicks 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);
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  for (int Number = 1; Number <= 20; Number++)
    ListBox1->Items->Add("Item " + IntToStr(Number));
}

 

Delphi Examples: 

{
The following example uses a list box containing a list of
strings, a button, and an edit box on a form. When the user
runs the application and clicks 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):
} 
procedure TForm1.Button1Click(Sender: TObject);
begin
  ListBox1.TopIndex := 2;
  Edit1.Text := IntToStr(ListBox1.TopIndex);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  Number: Integer;
begin
  for Number := 1 to 20 do
    ListBox1.Items.Add('Item ' + IntToStr(Number));
end;

 

ItemIndex 

Items 

Sorted

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!