Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

Get visible portion of ListView?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sin Jeong-hun - 19 Aug 2006 15:11 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.