Solved

Last Visible Item in a ListView

Posted on 2003-11-20
7
483 Views
Last Modified: 2008-03-10
I'm trying to get the last visibile item in a listview, you can easly get the top item with
the .topItem property. How do you get the last visible item? Thank you
0
Comment
Question by:modified_
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 9

Expert Comment

by:malharone
ID: 9791967
be more specific about the item of "last visibility"
give an example.
0
 

Author Comment

by:modified_
ID: 9793017
ok, for example if you have 100 total items in your list, but the listview window is small
and you're scrolled somewhere in the middle of the list. Say the top showing item in the
listview is at index 25, you can get this item by using ListView1.topItem. Now say the last
visible item in the scroll is at index 35, how would you get that item through programming? So you know what range of elements are currently displayed on the screen.
0
 

Expert Comment

by:durkin
ID: 9793106
You could try using the .GetItemAt() method of the listview. Just work out where the bottom of your listview is (using height, top etc. properties) and pass this postion to the above method and it returns the listviewitem there. If there is nothing there then the last item in your list must also be the last visible.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 27

Accepted Solution

by:
Dabas earned 125 total points
ID: 9794546
Hi modified_,
As you say yourself, ListView1.topitem gives you the item that appears at the top
ListView1.Height gives you the height of the control.
The only factor that you still need to know is the height of the ListView items.
This can be found using: ListView1.Items(0).GetBounds(ItemBoundsPortion.ItemOnly).Height)
You can now divide the height of the ListView by the height of the Items to know how many items are visible.


Dabas
0
 

Expert Comment

by:durkin
ID: 9794620
Dabas, I think both you and I are presuming that modified_'s listview is in details view. Is this correct?
0
 
LVL 27

Expert Comment

by:Dabas
ID: 9794709
durkin,
Yes, you are right, I am presuming the listview is in details view.
As far as I remember, I only use details view, and am sorry Microsoft did not set it as the default view!
From modified's second post, I tend to believe that he also is implying details view.

Now if it is NOT details view, then ListView1.Items(0).GetBounds(ItemBoundsPortion.ItemOnly).Width) will allow you to figure out how many items are being shown per row too


Dabas
0
 

Author Comment

by:modified_
ID: 9797698
Thanks Thats i was i was trying to figure out, i was working on how to get the syntax to do that Dabas. And yes i did mean detail view. Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question