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.
Unfortunately, activation email could not send to your email. Please try again.

Tap location on screen

Thread ID:

Created:

Updated:

Platform:

Replies:

130053 Apr 18,2017 05:16 PM Mar 23,2018 07:28 AM Xamarin.Forms 5
loading
Tags: SfDataGrid
Clint Anderson
Asked On April 18, 2017 05:16 PM

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?

Sivaraman Sivagurunathan [Syncfusion]
Replied On April 19, 2017 05:39 AM

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
 

 


Piotr Grzywa
Replied On March 20, 2018 05:46 AM

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

Suhasini  Suresh [Syncfusion]
Replied On March 21, 2018 11:33 PM

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  


Piotr Grzywa
Replied On March 22, 2018 10:04 AM

thanks for the quick and comprehensive answer

Suhasini  Suresh [Syncfusion]
Replied On March 23, 2018 07:28 AM

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  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;