How to handle TListBox scrolled all the way down to last TListBoxItem in Delphi XE8?

1.7k views Asked by At

I am trying to make a TListBox that initially loads 15 TListBoxItems in it and every time you scroll all the way to the bottom of the TListBoxItem add another 15 TListBoxItems. In a firemonkey multi-device project in Delphi XE8.

Now i can't figure out how to know if the user is scrolled all the way down in a TListBox. I've tried every event of the TListBox, but none of them seems to do it.

2

There are 2 answers

1
sddk On

If the platform is Windows you can try something like this

var
  i: Integer;
  x:Double;
Begin
  x := ListBox1.Height / ListBox1.ItemHeight;
  i :=  GetScrollPos(ListBox1.Handle, SB_VERT);
  if i + x >= ListBox1.Items.Count then
    ShowMessage('It is at the end of scroll');
End;
0
Dsm On

I think you need to come at it slightly laterally. Instead of thinking about it in terms of when the user scrolls to the bottom of the list, think about it in terms of when the last item in the list becomes visible, i.e. when the IsVisible property of the ListBox.ListItems[ ListBox.ListItems.Count - 1].IsVisible is TRUE.

This only becomes TRUE when the user has scrolled to the bottom of the list!

You could use the gesture manager or a simple timer to test the the status.