How to get group records while right click on Group Caption in WinForms DataGrid (SfDataGrid)?
WinForms DataGrid (SfDataGrid) does not provide the direct support to get the group records while right click on Group Caption (CaptionSummaryRow). You can get group records while right click on Group Caption (CaptionSummaryRow) by customization CellClick event in WinForms DataGrid (SfDataGrid).
private void SfDataGrid_CellClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellClickEventArgs e)
{
//check Right Click on Group Caption in SfDataGrid
if (e.MouseEventArgs.Button == MouseButtons.Right && (e.DataRow.RowType == RowType.CaptionCoveredRow || e.DataRow.RowType == RowType.CaptionRow))
{
//get the Grouped items
var groupRecords = (e.DataRow.RowData as Group).Records.ToList();
txtDisplayRecords.Text = "OrderID\tCustomerID\tCustomerName\tCountry\tShipCity\tIsShipped\t\n";
//itterate items in that group
foreach (var record in groupRecords)
{
//here customize based on your scenario
if (!record.IsRecords)
return;
//get the RowData of Grouped item one by one and type cast with underline business object
var dataRow = (record as RecordEntry).Data as OrderInfo;
txtDisplayRecords.Text += dataRow.OrderID + "\t" + dataRow.CustomerID + "\t\t" + dataRow.CustomerName + "\t" + dataRow.Country + "\t" + dataRow.ShipCity + "\t" + dataRow.IsShipped + "\t\n";
}
}
}
Take a moment to peruse the WinForms DataGrid - Selection documentation, where you can find about selection with code examples.
You can download the example from GitHub.