Articles in this section
Category / Section

How to get the X and Y coordinates when interacting with SfDataGrid?

1 min read

You can get the get the X and Y coordinates when interacting with Xamarin.Forms DataGrid by using SfDataGrid.RowColumnIndexToPoint method. You need to pass the RowColumnIndex for obtaining the coordinates.

You can get these coordinates in anywhere while interacting with SfDataGrid. Refer the below code example in which the X and Y coordinates are obtained by passing the RowColumnIndex in GridTapped, GridDoubleTapped and GridLongPressed events.

  <ContentPage.Content>   
    <syncfusion:SfDataGrid x:Name="datagrid"
                           AutoGenerateColumns="True"
                           ColumnSizer="Star"
                           ItemsSource="{Binding OrdersInfo}"
                           GridTapped="Datagrid_GridTapped"
                           GridDoubleTapped="Datagrid_GridDoubleTapped"
                           GridLongPressed="Datagrid_GridLongPressed"/>    
  </ContentPage.Content>

 

private void Datagrid_GridLongPressed(object sender, Syncfusion.SfDataGrid.XForms.GridLongPressedEventsArgs e)
        {
            Point point = datagrid.RowColumnIndexToPoint(e.RowColumnindex);
            double xCoordinate = point.X;
            double yCoordinate = point.Y;
        }
        private void Datagrid_GridDoubleTapped(object sender, Syncfusion.SfDataGrid.XForms.GridDoubleTappedEventsArgs e)
        {
            Point point = datagrid.RowColumnIndexToPoint(e.RowColumnIndex);
            double xCoordinate = point.X;
            double yCoordinate = point.Y;
        }
        private void Datagrid_GridTapped(object sender, Syncfusion.SfDataGrid.XForms.GridTappedEventsArgs e)
        {
            Point point = datagrid.RowColumnIndexToPoint(e.RowColumnindex);
            double xCoordinate = point.X;
            double yCoordinate = point.Y;
        }

Screenshot:

 

Note: Similarly, you can also get the RowColumnIndex based on the touch points using the SfDataGrid.PointToCellRowColumnIndex method.

 

Sample Link:

How to get the X and Y coordinates when interacting with SfDataGrid?

Conclusion

I hope you enjoyed learning about how to get the X and Y coordinates when interacting with SfDataGrid.

You can refer to our  Xamarin.Forms DataGrid feature tour page to know about its other groundbreaking feature representations. You can also explore our  Xamarin.Forms DataGrid documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied