How do i know, if particular item in ListView is shown in view?

3 posts, 1 answers
  1. Igor
    Igor avatar
    145 posts
    Member since:
    Jan 2011

    Posted 25 Jan 2014 Link to this post

    Hi, i want to know, if user can see the item at specifued position of ListView.
    Currently i am doing like that:

    bool isItemVisible(MyBusinessLogicClass c)
    {
      for (int y = listView.Height; y > 10; y -= 10)
      {
         var result = listView.ElementTree.GetElementAtPoint(new Point(5, y),
                x => (x is SimpleListViewVisualItem) && ((SimpleListViewVisualItem)x).Data.DataBoundItem == c);
                     
                 if (result != null)
                        return true;
        }
     
         return false;
     }


    Is there any other "right" way having such ability?
    Thanks!
  2. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 28 Jan 2014 Link to this post

    Hi Igor,

    Thank you for writing. 

    If I understand correctly, you are using RadListView with ViewType = ListView and you want to iterate over the currently visible items. If so, here is how you can do that:
    foreach (SimpleListViewVisualItem visualItem in ((SimpleListViewElement)radListView1.ListViewElement.ViewElement).ViewElement.Children)
    {
        if (yourCondition)
        {
            //do something
        }
    }

    I hope this helps. 

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Igor
    Igor avatar
    145 posts
    Member since:
    Jan 2011

    Posted 29 Jan 2014 in reply to Stefan Link to this post

    Hi Stefan!

    great this works!
    I've made the following snippet:

    bool isItemVisible(MyBusinessLogicClass c)
    {
                if ((listView.ListViewElement.ViewElement).ViewElement.Children.Where(x => ((SimpleListViewVisualItem)x).Data.DataBoundItem == c).Count() == 0)
                    return false;
     
                return true;
    }

    Thank you!
Back to Top