How to perform long press operation in Xamarin.iOS SfDataGrid?
SfDataGrid 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.
Refer the following code example that explains how to use the GridLongPressed event and display a pop up message when long pressing the rows.
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 grid_GridLongPressed(object sender, GridLongPressedEventsArgs e) { UIAlertView alert1 = new UIAlertView ("LongPress", "Long Pressed Row is" + Convert.ToString (e.RowColumnindex.RowIndex), null, "ok"); alert1.Show (); } }
The following screenshot shows the final outcome upon execution of the above code which displays the row index as a pop up upon Long Press