Articles in this section
Category / Section

How to delete a row when long pressing on a data row in Xamarin.iOS DataGrid?

1 min read

Xamarin.iOS DataGrid fires the SfDataGrid.GridLongPressed event when the grid is long pressed. You can perform any desired operation upon long pressing by handling the GridLongPressed event. The GridLongPressed event provides you with the arguments “RowIndex” and “RowData” (the underlying data associated with the row based on the row type) there by allowing you to customise the long press event based on the requirements.

The SfDataGrid fires this event for all type of rows such as header row, caption summary rows and data rows. When you long press the header row the associated GridColumn of the long pressed header cell is passed as RowData. When you long press the data rows, the underlying data object associated with the long pressed row is passed as RowData. When you long press the caption rows, the group information associated with the long pressed caption row is passed as RowData. Thus by checking whether the RowData is the underlying data object you can delete the respective row in SfDataGrid using the RowColumnIndex or the RowData.

Refer the following example which illustrates how to delete a row in a SfDataGrid when long pressing it by handling the GridLongPressed event.

public partial class ViewController : UIViewController
    SfDataGrid grid= new SfDataGrid();
    ViewModel viewModel=new ViewModel();
    public override void ViewDidLoad ()
         base.ViewDidLoad ();
         View.BackgroundColor = UIColor.White;
         grid.ItemsSource = viewModel.ProductDetails;
         grid.BackgroundColor = UIColor.White;
         grid.GridLongPressed += grid_GridLongPressed;
         View.AddSubview (grid);
    public override void ViewDidLayoutSubviews ()
         this.grid.Frame = new CGRect (0, 20, View.Frame.Width, View.Frame.Height);
         base.ViewDidLayoutSubviews ();
    void sfGrid_GridLongPressed(object sender, GridLongPressedEventsArgs e)
        if(e.RowData is ProductInfo)
            viewModel.ProductDetails.RemoveAt(e.RowColumnindex.RowIndex - 1);
            UIAlertView alert1= new UIAlertView(“LongPress”, “Deleted row is” + Convert.ToString(e.RowColumnIndex.RowIndex),null, “OK”)


The following screenshot shows the final outcome upon execution of the above code.


I hope you enjoyed learning about how to delete a row when long pressing on a data row in Xamarin.iOS DataGrid.

You can refer to our Xamarin.iOS 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.iOS 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 forumsDirect-Trac, or feedback portal. We are always happy to assist you!


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