Getting the ListViewDataItem from mouse position on a ListView

3 posts, 1 answers
  1. Evald
    Evald avatar
    2 posts
    Member since:
    Nov 2015

    Posted 23 Nov 2015 Link to this post

    Dear Telerik,

     I'm currently using the version 2013.2.612.40. My requirement are to get the ListViewDataItem when the user right click. I'm using the DetailsView.

    Basically the user right click in one item, the last get selected and later i can do some other processing.

    Unfortunately i cannot get it done. I have seen the following post that does not work http://www.telerik.com/forums/select-an-item-in-listbox-control-on-mousedown-event

    Any help please

     

  2. Answer
    Dess
    Admin
    Dess avatar
    1609 posts

    Posted 23 Nov 2015 Link to this post

    Hello Evald,

    Thank you for writing.

    Here is a sample code snippet demonstrating how to access the ListViewDataItem when the user right clicks in DetailsView:
    public Form1()
    {
        InitializeComponent();
        this.radListView1.ViewType = Telerik.WinControls.UI.ListViewType.DetailsView;
        this.radListView1.MouseDown += radListView1_MouseDown;
    }
     
    private void radListView1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Right)
        {
            DetailListViewDataCellElement cell = this.radListView1.ElementTree.GetElementAtPoint(e.Location) as DetailListViewDataCellElement;
            if (cell!=null)
            {
                ListViewDataItem dataItem = cell.Row;
            }
        }
    }

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Evald
    Evald avatar
    2 posts
    Member since:
    Nov 2015

    Posted 23 Nov 2015 in reply to Dess Link to this post

    Hello Dess,

    Code snippet meets my requirements.

    Thank you

Back to Top