We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to get the SelectedRecord when RowBased selection enabled in GridGroupingControl - From 180948

Hi,

I need help with GGC and event SelectedRecordsChanged

My problem is, when I select range of cells, I want to sum value of those cells, like excel


- If I use

gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.MultiExtended;

gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.None;

=> event fired, but not what I desire, and value not sum


Attachment: CS_c9d4bde8.zip


1 Reply

VS Vijayarasan Sivanandham Syncfusion Team March 8, 2023 12:12 PM UTC

Hi Hieudt,

When you set the ListBoxSelectionMode property to a value other than None and the AllowSelection property to None in the GridGroupingControl, a record-based selection is used. The SelectedRecordsChanging and SelectedRecordsChanged events are triggered only when using the record-based selection. In this case, the selected records can be found in the Table.SelectedRecords collection.

So, your requirement to sum the values contained in the selected range of cells in the GridGroupingControl can be achieved by using the Table.SelectedRecords property. Refer to the below code snippet,

//Case 1: Record based selection

gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.MultiExtended;

gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.None;

 

//Case 1: Record based selection

foreach (var range in this.gridGroupingControl1.Table.SelectedRecords)

{                       

     Record rec = range.Record;

     Console.WriteLine(rec.GetValue(style.TableCellIdentity.Column.Name));

 

     if (column.FieldDescriptor.GetPropertyType() == typeof(decimal))

     {

         value += decimal.Parse(rec.GetValue(style.TableCellIdentity.Column.Name).ToString());

     }

}                


UG Link:
https://help.syncfusion.com/windowsforms/gridgrouping/selections#record-based-selection

KB Link :
https://www.syncfusion.com/kb/5278/how-to-retrieve-and-modify-the-selected-record-in-the-winforms-gridgroupingcontrol

Find the sample in the attachment.


Regards,

Vijayarasan S


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: GridGroupingControlDemo_6579cb02.zip

Loader.
Up arrow icon