How to clear grouping when long pressing on a caption row in Xamarin.Android DataGrid?
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. 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 a “Group” you can clear the grouping in SfDataGrid by clearing the SfDataGrid.GroupColumnDescriptions collection.
Refer the following example which illustrates clearing the grouping in a SfDataGrid when long pressing a caption row by handling the GridLongPressed event.
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) { if (e.RowData is Group) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.SetTitle("Clear Grouping…"); alert.SetMessage("Are you sure to remove grouping from the grid?"); alert.SetPositiveButton("Clear", (senderAlert, args) => { sfGrid.GroupColumnDescriptions.Clear(); Toast.MakeText(this, "Grouping Cleared", ToastLength.Short).Show(); }); alert.SetNegativeButton("Cancel", (senderAlert, args) => { Toast.MakeText(this, "Cancelled!", ToastLength.Short).Show(); }); Dialog dialog = alert.Create(); dialog.Show(); } } }
The following screenshot shows the final outcome upon execution of the above code.
You can download a working sample for this KB from the below link:http://www.syncfusion.com/downloads/support/directtrac/general/ze/CustomCellSample-1501493432
Conclusion
I hope you enjoyed learning about how to clear grouping when long pressing on a caption row.
You can refer to our Xamarin.Android DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
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!