This is a migrated thread and some comments may be shown as answers.

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

2 Answers 162 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Igor
Top achievements
Rank 2
Igor asked on 25 Jan 2014, 07:19 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 28 Jan 2014, 12:50 PM
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 >>
0
Igor
Top achievements
Rank 2
answered on 29 Jan 2014, 04:38 PM
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!
Tags
ListView
Asked by
Igor
Top achievements
Rank 2
Answers by
Stefan
Telerik team
Igor
Top achievements
Rank 2
Share this question
or