New to Telerik UI for .NET MAUIStart a free 30-day trial

Cell Info on Right Click in DataGrid

Updated over 6 months ago

Environment

VersionProductAuthor
5.1.0Telerik UI for .NET MAUI ChartDobrinka Yordanova

Description

This how-to article describes how to get the cell info on a right click in the Telerik UI for .NET MAUI DataGrid control.

Solution

1. Add DataGrid to the Page:

XAML
<Grid>
	<telerik:RadDataGrid x:Name="dataGrid" />
</Grid>

2. Add Sample data to the RadDataGrid.ItemsSource:

C#
this.dataGrid.ItemsSource = new List<Data>
{
	new Data { Country = "India", Capital = "New Delhi"},
	new Data { Country = "South Africa", Capital = "Cape Town"},
	new Data { Country = "Nigeria", Capital = "Abuja" },
	new Data { Country = "Singapore", Capital = "Singapore" }
};

3. Add the Data class:

C#
public class Data
{
	public string Country { get; set; }
	public string Capital { get; set; }
}

4. Add TapGestureRecognizer for right-click and get the position of the internal ScrollView in the DataGrid on right click and use the DataGrid HitTestService.CellInfoFromPoint() method , to get the cell info for the concrete position.

C#
RadScrollView sv = null;
foreach (var child in this.dataGrid)
{
	if (child is RadScrollView)
	{
		sv = child as RadScrollView;
		break;
	}
}

var content = sv.Content;

var tap = new TapGestureRecognizer()
{
	Buttons = ButtonsMask.Secondary
};

tap.Tapped += (s, e) =>
{
	var position = e.GetPosition(content);
	var hitTestService = this.dataGrid.HitTestService;
	var cellInfo = hitTestService.CellInfoFromPoint(position.Value);

	// sample visualization the data in the cell when right-click
	App.Current.MainPage.DisplayAlert("Right click on",""+cellInfo.Value,"ОК");
};

5. Finally, add this gesture to the DataGrid GestureRecognizers.

C#
this.dataGrid.GestureRecognizers.Add(tap);
In this article
EnvironmentDescriptionSolution
Not finding the help you need?
Contact Support