How to delete a row when long pressing on a data row in Xamarin.Forms DataGrid?
You can delete a row when long pressing on a data row by hooking the SfDataGrid.GridLongPressed event.
Refer the below code example in which the SfDataGrid is grouped by a column 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 deleting a row in SfDataGrid when long pressing on it.
private void Datagrid_GridLongPressed(object sender, Syncfusion.SfDataGrid.XForms.GridLongPressedEventsArgs e) { viewModel.OrdersInfo.Remove((StudentInfo)e.RowData); }
Screenshot:
Sample Link:
How to delete a row when long press on a data row?
Conclusion
I hope you enjoyed learning about how to delete a row when long pressing on a data row in Xamarin.Forms DataGrid.
You can refer to our Xamarin.Forms DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Xamarin.Forms DataGrid example 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!