[RESOLVED] VB2010 Listview: determine which items are visible-VBForums
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
    181

    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
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    88,644

    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.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  3. #3
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.