get Location of radListView1.SelectedItem

3 posts, 1 answers
  1. Froggie
    Froggie avatar
    29 posts
    Member since:
    Jan 2012

    Posted 15 Mar 2012 Link to this post

    How can I retrieve the Location (ideally the middle of the control) of radListView1.SelectedItem?
  2. Answer
    Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 19 Mar 2012 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Froggie
    Froggie avatar
    29 posts
    Member since:
    Jan 2012

    Posted 20 Mar 2012 Link to this post

    Thank you. That solved my problem.
Back to Top