Articles in this section
Category / Section

How to perform long press operation in Xamarin.Forms SfDataGrid?

1 min read

You can perform the long press operations in Xamarin.Forms DataGrid by hooking the SfDataGrid.GridLongPressed event.

Refer the below code example in which the SfDataGrid is loaded and the GridLongPressed event is hooked.

<ContentPage.BindingContext>
    <local:ViewModel x:Name="viewModel"/>
  </ContentPage.BindingContext>
<ContentPage.Content>
  <syncfusion:SfDataGrid x:Name="datagrid"
                         ColumnSizer="Star"
                         AutoGenerateColumns="True"
                         ItemsSource="{Binding OrdersInfo}"
                         GridLongPressed="Datagrid_GridLongPressed">
</syncfusion:SfDataGrid>
</ContentPage.Content>

 

The below code illustrates displaying a DisplayAlert to display the underlying data of the long pressing row.

private void Datagrid_GridLongPressed(object sender, Syncfusion.SfDataGrid.XForms.GridLongPressedEventsArgs e)
        {
            //You can perform any operation here based on the requirements
 
            //Code to display a DisplayAlert showing the underlying data.
            string name = (e.RowData as StudentInfo).StudentName;
            string regNo = (e.RowData as StudentInfo).StudentRegno;
            DisplayAlert(name, "RegNO"+ regNo.ToString(), "Cancel");
        }

 

Screenshot:

Table

 

Sample Link:

How to perform long press operation in SfDataGrid?


Conclusion

I hope you enjoyed learning about how to perform long press operations in Xamarin 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 sign in to leave a comment
Access denied
Access denied