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

When right clicking, how can I get the ViewModel object that represents the row?

2 Answers 80 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 09 May 2018, 12:57 PM

If a row is selected I can access the selectedItem, but when nothing is yet selected I don't see a way to find which row that was right-clicked.

Is it possible?

2 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 14 May 2018, 08:50 AM
Hello Andrew,

You can use the HitTestService of the DataGrid to get the cell you have tapped. That service provides a method called CellInfoFromPoint that will return an information for the tapped item by only passing the position that you have tapped:
private void DataGrid_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
    if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
    {
        var currentPoint = e.GetCurrentPoint(this);
        if (currentPoint.Properties.IsRightButtonPressed)
        {
            var cell = this.DataGrid.HitTestService.CellInfoFromPoint(currentPoint.Position);
 
            //Implement your logic here
        }
    }
 
}

I hope this will help you.

Regards,
Nasko
Progress 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
Andrew
Top achievements
Rank 1
answered on 16 May 2018, 01:49 PM

I was able to make something work with your example.

Thank you Nasko.

Tags
DataGrid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or