How to update the summaries immediately upon changing a field and not wait until I leave the row in WinForms GridGroupingControl?
Update the summaries
By default, the summaries are refreshed only when you leave the current row to another row because the edited values are not saved in the underlying DataSource when the CurrentCell is edited and navigated in the same row itself. The summary value is calculated only when the changes are made in the DataSource.
Solution:
Step 1: By using Built-in property:
There is a property in the TableDescriptor.Fields collection called the ForceImmediateSaveValue. By setting this property value to true, the changes made in the CurrentCell is immediately saved into the underlying DataSource while leaving the CurrentCell to the same row itself. Therefore, the summaries are updated automatically.
C#
//Forces the GridGroupingControl to save the edited values while leaving the CurrentCell. foreach (FieldDescriptor col in this.gridGroupingControl1.TableDescriptor.Fields) this.gridGroupingControl1.TableDescriptor.Fields[col.Name].ForceImmediateSaveValue = true;
VB
'Forces the GridGroupingControl to save the edited values while leaving the CurrentCell. For Each col As FieldDescriptor In Me.gridGroupingControl1.TableDescriptor.Fields Me.gridGroupingControl1.TableDescriptor.Fields(col.Name).ForceImmediateSaveValue = True Next col
Step 2: By using Work Around
By using the CurrentRecordContextChange event handler, you can also update the summary values by invalidating the summary when the value of the current record is changed.
C#
//Hooks the CurrentRecordContextChange event. this.gridGroupingControl1.CurrentRecordContextChange +=gridGroupingControl1_CurrentRecordContextChange; private void gridGroupingControl1_CurrentRecordContextChange(object sender, Syncfusion.Grouping.CurrentRecordContextChangeEventArgs e) { //Checks whether the Current field value is changed or not. if(e.Action == CurrentRecordAction.CurrentFieldChanged) { //Ends the current editing this.gridGroupingControl1.CurrencyManager.EndCurrentEdit(); //Invalidates the Summary to update the value. this.gridGroupingControl1.Table.InvalidateSummary(); } }
VB
'Hooks the CurrentRecordContextChange event. Private Me.gridGroupingControl1.CurrentRecordContextChange += AddressOf gridGroupingControl1_CurrentRecordContextChange Private Sub gridGroupingControl1_CurrentRecordContextChange(ByVal sender As Object, ByVal e As Syncfusion.Grouping.CurrentRecordContextChangeEventArgs) 'Checks whether the Current field value is changed or not. If e.Action = CurrentRecordAction.CurrentFieldChanged Then 'Ends the current editing. Me.gridGroupingControl1.CurrencyManager.EndCurrentEdit() 'Invalidates the Summary to update the value. Me.gridGroupingControl1.Table.InvalidateSummary() End If End Sub
Samples: