Solved

Last Visible Item in a ListView

Posted on 2003-11-20
7
488 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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:…

734 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