How to perform long press operation in 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 which illustrates how to hook the GridLongPressed event and display a “Toast” message when long clicking the rows.
public class MainActivity : Activity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SfDataGrid sfGrid = new SfDataGrid(this); sfGrid.ItemsSource = new ViewModel().ProductDetails; sfGrid.GridLongPressed += sfGrid_GridLongPressed; SetContentView(sfGrid); } void sfGrid_GridLongPressed(object sender, GridLongPressedEventsArgs e) { Toast.MakeText(this, "Long pressed Row is " + e.RowColumnindex.RowIndex.ToString(), ToastLength.Short).Show(); }
The following screenshot shows the final outcome upon execution of the above code displaying the row index of the long pressed row in a toast.