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

get Location of radListView1.SelectedItem

2 Answers 173 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Froggie
Top achievements
Rank 1
Froggie asked on 15 Mar 2012, 12:14 PM
How can I retrieve the Location (ideally the middle of the control) of radListView1.SelectedItem?

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Todorov
Telerik team
answered on 19 Mar 2012, 10:25 AM
Hello Froggie,

Thank you for your question.

The following code snippet demonstrates how you can achieve the desired functionality:
public Point GetSelectedItemLocation(RadListView listView)
{
    if(listView.SelectedItem == null)
        return Point.Empty;
 
    BaseListViewVisualItem visualItem = listView.ListViewElement.ViewElement.GetElement(listView.SelectedItem);
     
    if (visualItem == null)
        return Point.Empty;
 
    return visualItem.ControlBoundingRectangle.Location;
}

Note that this method will only work when the selected item is visible inside the client area of the control. Otherwise, there will not be an actual visual item associated to the selected item due to the virtualization mechanism of RadListView.

I hope you find this useful. In case you have any further questions, do not hesitate to ask.

Kind regards,
Ivan Todorov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Froggie
Top achievements
Rank 1
answered on 20 Mar 2012, 01:29 PM
Thank you. That solved my problem.
Tags
ListView
Asked by
Froggie
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Froggie
Top achievements
Rank 1
Share this question
or