Solved

Last Visible Item in a ListView

Posted on 2003-11-20
7
481 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unable to upgrade to .Net 4.6.2 on Server 2012r2 2 43
Tool Box 2 35
Runtime Exceptions when trying to submit data 28 37
VB.NET Repostiory Pattern 7 16
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now