How to set the ViewportPostion of the item selected in TListView inside the TVertScrollBox

420 views Asked by At

I have a TListView containing a hundred items inside the TVertScrollBox. I wanted to set the ViewportPosition of the selected item (done by code) in the TListView. The TListView is not scrollable, only the TVertScrollBox is scrollable.

With the 100 items in the TListView, I do not want my user to scroll the entire list of items but instead, upon selection using code, it automatically set the ViewportPostion to selected item.

I am trying to figure out from the following code on how to change the 0 to the variable number of the item selected.

VertScrollBox1.ViewportPosition := PointF(VertScrollBox1.ViewportPosition.X, 0);

I will appreciate any help or clue on this.

1

There are 1 answers

3
fpiette On BEST ANSWER

Assuming the TListView is inside a TVertScrollBox and TListView.Height is large enough so that there is not scrollbar at all, then to have the viewport set so that TListView item number N is at the top (You get N by searching for data), then to scroll the item N in view, you do:

VertScrollBox1.ViewportPosition := PointF(VertScrollBox1.ViewportPosition.X,
                                          ListView1.ItemAppearance.ItemHeight * N);