How to dynamically scroll in Tlistbox Delphi xe5

3.5k views Asked by At

TListbox.topIndex is not apparent in Delphi xe5. How do I perform a similar function ? I would like to have the listbox scroll so that the selected item is at the top of the listbox.

I have found other examples where I can set ListBox.itemIndex, but that doesn't scroll so that the selected item is at the top of the listbox.

Thank you in advance.

2

There are 2 answers

1
J__ On BEST ANSWER

I have used this code which works:

var
  THackListBox = type TListBox;
begin
  THackListBox(ListBox1).VScrollBar.Value := 0;

The VScrollBar property is protected but this method exposes the property and allows the value to be set to zero.

0
Remy Lebeau On

On Windows, the VCL TListBox has a public TopIndex property, which internally uses the LB_SETTOPINDEX message.

There is no equivalent in the FireMonkey TListBox. The only option I see would be to call the ListBox's ScrollTo() method to manually scroll the ListBox so the target list item appears where you want it to be.