DataGrid New Row BottomRows Aggregate

Posted by: patrick.muellner on 18 September 2022, 5:16 pm EST

    • Post Options:
    • Link

    Posted 18 September 2022, 5:16 pm EST

    Hi, I work with a DataGrid. Here I have some Numeric Columns with an aggregate function and one BottomRow where the sum of each column is shown. Also the use can add new rows.

    My problem is now, when the user add a new row, that after committing the cell the sum is not calculating.

    If I edit a “normal” row – the sum is calculating after committing the cell. How can I solve this problem?

    Regards

  • Posted 18 September 2022, 10:30 pm EST

    Hi Patrick,

    We are unable to replicate this behavior at our end i.e., Sum is updating after adding a new row and committing the particular cell. You can check our product sample at : “Documents\ComponentOne Samples\WPF\v4.6.2\C1.WPF.DataGrid\CS\DataGridSamples”

    Steps to replicate:

    1. Open “DataGridSamples” project in VisualStudio.
    2. Open “GroupTotalPage.xaml”.
    3. Change CanUserAddRows property to True.
    4. Run the Sample.
    5. Navigate to “Grand Total” tab.
    6. Click on last row to add a new row.
    7. Enter values to the cell of newly added row.

    observation - Aggregate will be update after committing edit.

    Still, if you are facing issue then please provide a sample replicating the behavior. So, that we can assist you accordingly.

    Regards, Nitin

  • Posted 19 September 2022, 12:29 am EST

    Hi, I include you a video. It doesn’t work - after edit the value I press tab. I have to commit the row then it works. But not, if I commit the cell. Regards

  • Posted 19 September 2022, 12:30 am EST

  • Posted 19 September 2022, 2:46 pm EST

    Hi Patrick,

    This is a design behavior. Aggregate updates after row edit commit. Tab : Commits Cell Edit and Commits Row Edit(if last cell of row) Enter : Commits Row Edit.

    You can try with normal rows, pressing tab will commit cell and will not update aggregate like your attached video. While pressing Enter on normal row or new row, it commits row edit and update the aggregate.

    Regards, Nitin

  • Posted 19 September 2022, 3:48 pm EST

    Hi, but when I edit “normal” rows I add this code and it works:

    
          Private Sub grd_CommittedEdit(sender As Object, e As DataGridCellEventArgs) Handles grd.CommittedEdit
             Dim objSummary = DirectCast(Me.grd.BottomRows.LastOrDefault, Summaries.DataGridSummaryRow)
             objSummary?.Refresh()
          End Sub
    
    

    But with new rows it doesn’t works. Is there no workaround?

    Regards

  • Posted 19 September 2022, 9:50 pm EST

    Hi Patrick,

    JFYI, while editing a new row, it will not update to the bounded collection until the new row commits edit mode. However, we have a workaround for this solution: While editing a new row we need to commit new row edit. So, that it will update to the Collection with default values. And then immediately starts editing to the last added row. Now you can achieve same behavior in Normal row and New row i.e., after pressing Tab key the Summary Row will update. For that, you can handle BeginningNewRow event as :

    C#:

    
            private async void BeginningNew_Row(object sender, DataGridBeginningNewRowEventArgs e)
            {
                var selection = grid.CurrentCell;
                await System.Threading.Tasks.Task.Delay(100);
                grid.EndNewRow(true);
                grid.BeginEdit(selection.Row.Index - 1, selection.Column.Index);
            }
    
    

    VB:

    
    Private Async Sub BeginningNew_Row(ByVal sender As Object, ByVal e As DataGridBeginningNewRowEventArgs)
        Dim selection = grid.CurrentCell
        Await System.Threading.Tasks.Task.Delay(100)
        grid.EndNewRow(True)
        grid.BeginEdit(selection.Row.Index - 1, selection.Column.Index)
    End Sub
    
    

    Please refer the attached sample for the same : DataGridSample_Mod.zip

    Kind Regards, Nitin

  • Posted 6 October 2022, 4:09 pm EST

    Hi again,

    I have following problems again: 1.) When I put the FIRST value (first key down) in the cell, the summary row calculate. But after that, the summary row only calculating if I commit the edit. Video included.

    2.) When I move very fast in the cells I got following exception: Fehlermeldung: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt. Fehlertyp: System.NullReferenceException StackTrace: bei C1.WPF.DataGrid.DataGridCellPresenter.GoToEditingState() bei C1.WPF.DataGrid.DataGridCellPresenter.UpdateEditingCell() bei C1.WPF.DataGrid.DataGridCellsPanel.SetEditingCell(ViewColumn viewColumn) bei C1.WPF.DataGrid.DataGridRowPresenter.SetEditingCell(ViewColumn viewColumn) bei C1.WPF.DataGrid.DataGridView.UpdateEditingCell(DataGridCell #45, DataGridCell #hUb) bei C1.WPF.DataGrid.DataGridView.#5ky(Object #aE, PropertyChangedEventArgs

    1 #tQ)    bei C1.WPF.DataGrid.DataGridModel.OnCurrentEditingCellChanged(PropertyChangedEventArgs
    1 e) bei C1.WPF.DataGrid.DataGridFocusAndEditingManager.BeginEdit() bei C1.WPF.DataGrid.DataGridModel.BeginCellEdit() bei C1.WPF.DataGrid.DataGridView.BeginCellEdit(RoutedEventArgs #q1g) bei C1.WPF.DataGrid.DataGridDefaultInputHandlingStrategy.HandleKeyDown(Key #bU, Boolean #45e, Boolean #kPb, Boolean& #Icb, Object #T3g, KeyEventArgs #tQ) bei C1.WPF.DataGrid.DataGridDefaultInputHandlingStrategy.HandleKeyDown(KeyEventArgs e) bei C1.WPF.DataGrid.C1DataGrid.b__273_0(Object s, KeyEventArgs e) bei System.Windows.Input.KeyEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) bei System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) bei System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) bei System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) bei System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) bei System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) bei System.Windows.Input.InputManager.ProcessStagingArea() bei System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) bei System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) bei System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey) bei System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled) bei System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers) bei System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param) bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

    bandicam 2022-10-07 07-06-47-902.zip

  • Posted 6 October 2022, 8:22 pm EST

    Hi Patrick,

    1. We are unable to replicate this behavior at our end. Could you please provide a small sample to investigate the issue?

    2. You can resolve this issue by updating BeginningNewRow event as:

           private void BeginningNew_Row(object sender, DataGridBeginningNewRowEventArgs e)
            {
                var selection = grid.CurrentCell;
                Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Loaded, new Action(() =>
                {
                    grid.EndNewRow(true);
                    grid.BeginEdit(selection.Row.Index - 1, selection.Column.Index);
                }));            
            }

    Please refer the attached sample for the same: DataGridSample_Mod2.zip

    Best Regards,

    Nitin

  • Posted 6 October 2022, 8:39 pm EST

    Perfect .

    I found another solution.

    Regards

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels