Is it possible to get current visible rect when there is a scrollbar on
the ListBox?
Say, if the ListBox is in Details mode, and there are 1000 lines. The
user has scrolled down to 500th line and currently 500~540th lines are
visible. Is there any way to get this number (500~540?) or virtual
Rectable of visible area compared to the whole ListView rectable?
Dave Sexton - 20 Aug 2006 02:58 GMT
Hi,
In 2.0 (I'm not sure about 1.*) there is a method called GetItemRect. I haven't tried myself, but maybe you can use the TopItem
property, GetItemRect and the Height property of the ListView to determine the number of lines that are visible. Here's some code
(hasn't been tested):
int firstVisibleIndex = listView.TopItem.Index;
// TODO: verify heightOfFirstItem is not zero
int heightOfFirstItem = listView.GetItemRect(firstVisibleIndex, ItemBoundsPortion.Entire).Height;
// assuming each item has the same height (I think this is true for list view and details view)
int nVisibleLines = (int) Math.Ceiling(listView.Height / heightOfFirstItem);
int lastVisibleIndexInDetailsMode = firstVisibleIndex + nVisibleLines;
// NOTE: This will not work in list mode without accounting for multiple items per line.
Please let me know if that works for you.

Signature
Dave Sexton
> Is it possible to get current visible rect when there is a scrollbar on
> the ListBox?
[quoted text clipped - 3 lines]
> visible. Is there any way to get this number (500~540?) or virtual
> Rectable of visible area compared to the whole ListView rectable?
Claes Bergefall - 21 Aug 2006 15:41 GMT
P/Invoke LVM_GETCOUNTPERPAGE and use the TopItem property. From those two
you can figure out which items are currently visible (at least I think this
is what you asked for).
/claes
> Is it possible to get current visible rect when there is a scrollbar on
> the ListBox?
[quoted text clipped - 3 lines]
> visible. Is there any way to get this number (500~540?) or virtual
> Rectable of visible area compared to the whole ListView rectable?