Results 1 to 3 of 3

Thread: [RESOLVED] VB2010 Listview: determine which items are visible

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    new zealand (kiwi)!
    Posts
    202

    Resolved [RESOLVED] VB2010 Listview: determine which items are visible

    With the Listview in Details view:
    When showing a long (scrolling) list:
    Is there an (easy) way to return the index's of which range of items are currently visible in the control?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: VB2010 Listview: determine which items are visible

    There's nothing specific that I'm aware of, but you could probably use the GetItemAt and/or GetItemRect methods and deduce the first and last items from that.

    Note that I didn't know the answer to your question so I just opened the MSDN documentation for the ListView and had a look to see what was available. If I can do that, you can do that.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: VB2010 Listview: determine which items are visible

    try this:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Dim visibleRange = (From item In ListView1.Items _
    3.                        Let lvi = DirectCast(item, ListViewItem) _
    4.                        Where lvi.Bounds.Top > ListView1.GetItemRect(0).Height AndAlso lvi.Bounds.Bottom < ListView1.Height _
    5.                        Select lvi.Index).ToArray
    6.     MsgBox(String.Join(",", Array.ConvertAll(visibleRange, Function(i) i.ToString)))
    7. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width