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

Getting the ListViewDataItem from mouse position on a ListView

2 Answers 869 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Evald
Top achievements
Rank 1
Evald asked on 23 Nov 2015, 11:20 AM

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 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Nov 2015, 12:15 PM
Hello ,

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
0
Evald
Top achievements
Rank 1
answered on 23 Nov 2015, 01:05 PM

Hello Dess,

Code snippet meets my requirements.

Thank you

Tags
ListView
Asked by
Evald
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Evald
Top achievements
Rank 1
Share this question
or