We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Tap location on screen

How would I go about getting the coordinates on the screen of where the user has tapped, or double tapped the data grid.  I am displaying a custom popup menu when the user is interacting with the grid, but I need to place this menu approximately where the user has tapped.  I can get the row data and the row and column indices from my GridTappedEventsArgs.  Is there a way to use that information to consistently get the tap location?

5 Replies

SS Sivaraman Sivagurunathan Syncfusion Team April 19, 2017 09:39 AM UTC

Hi Clint Anderson,

Thanks for contacting Syncfusion Support.

We have checked your query. You can achieve your requirement to display a custom view when interacting on SfDataGrid using the SfDataGrid.RowColumnIndexToPoint method.

The below code
example illustrates how to display a custom view as popup menu in SfDataGrid. 
 
public partial class MainPage : ContentPage 
{ 
    private Label popupLabel; 
    private bool ispopupDisplayed = false; 
    private string currentColumnName; 
    public MainPage() 
    { 
        InitializeComponent(); 
        CreateToolTip(); 
        datagrid.GridDoubleTapped += Datagrid_GridDoubleTapped; 
        datagrid.GridTapped += Datagrid_GridTapped; 
    } 
 
    private void Datagrid_GridTapped(object sender, GridTappedEventsArgs e) 
    { 
        relativeLayout.Children.Remove(popupLabel); 
        ispopupDisplayed = false; 
    } 
    public void CreateToolTip() 
    { 
        popupLabel = new Label(); 
        popupLabel.HorizontalTextAlignment = TextAlignment.Center; 
        popupLabel.VerticalTextAlignment = TextAlignment.Center; 
        popupLabel.WidthRequest = 90; 
        popupLabel.HeightRequest = 50; 
        popupLabel.BackgroundColor = Color.Gray; 
        popupLabel.TextColor = Color.Black; 
    } 
    private void Datagrid_GridDoubleTapped(object sender, GridDoubleTappedEventsArgs e) 
    { 
        if (!ispopupDisplayed) 
        { 
            currentColumnName = datagrid.Columns[e.RowColumnIndex.ColumnIndex].MappingName; 
            var point = datagrid.RowColumnIndexToPoint(e.RowColumnIndex); 
            relativeLayout.Children.Add(popupLabel, Constraint.Constant(point.X + 50), Constraint.Constant(point.Y + 30)); 
            var rowData = datagrid.GetRecordAtRowIndex(e.RowColumnIndex.RowIndex); 
            var cellValue = datagrid.GetCellValue(rowData, currentColumnName); 
            popupLabel.Text = cellValue.ToString(); 
            ispopupDisplayed = true; 
        } 
        else 
        { 
            relativeLayout.Children.Remove(popupLabel); 
            ispopupDisplayed = false; 
        } 
    } 
} 



We have prepared a sample based on your requirement for your reference and you can download the same from the below link.

Sample Link:
http://www.syncfusion.com/downloads/support/forum/130053/ze/pointToIndex1113414939

Regards,
Sivaraman
 

 



PG Piotr Grzywa March 20, 2018 09:46 AM UTC

In latest version of VS 2017 and Xamarin.Forms 2.5.0.280555   popupLabel display always on first coordinates
If I add CreateToolTip(); in code work good.

  CreateToolTip();
  relativeLayout.Children.Add(popupLabel, Constraint.Constant(point.X + 50), Constraint.Constant(point.Y + 30));



My project :www.kupse.pl/www/GridTest.7z   password iks


SS Suhasini  Suresh Syncfusion Team March 22, 2018 03:33 AM UTC

Hi Clint, 
 
Thanks for your update. 
 
We are able to reproduce the issue. This is the frame work issue in RelativeLayout, when updating to Xamarin.Forms version 2.5.0.280555.  
 
We have prepared  a sample to reproduce the issue in a simple scenario, where the button is added to the grid. Clicking on the button should layout the popupLabel at different points.  Please find the sample reproducing the issue in a simple scenario in the below link. 
 
 
We will report it in Bugzilla and update you the further details on or before 23rd March 2018. 
 
Regards, 
Suhasini  



PG Piotr Grzywa March 22, 2018 02:04 PM UTC

thanks for the quick and comprehensive answer


SS Suhasini  Suresh Syncfusion Team March 23, 2018 11:28 AM UTC

Hi Clint, 
 
Thanks for your update. 
 
We reported the issue “When a child is added to the relative layout in run time and its layout position is changed in run time, position is not updated” in the Frame work. Please find the reported issue link below which you can follow up this issue further regarding this issue. 
 
 
Regards, 
Suhasini  


Loader.
Live Chat Icon For mobile
Up arrow icon