Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3565
WinGrid group by summary totals not adding up correctly
posted

I have a project estimation application that is currently in use where I have a grid displaying summary data that is using two group by columns. The final screen in the application is similar to a final estimated cost of a project grouped by a major category and sub categories. For example, materials, engineering and labor are the major categories and then each one has subcategories. The user can then adjust factors such as percentage mark up,  percentage risk and sales commission to add to the estimate cost and arrive at a final sales price that is submitted to a potential customer. When the user makes a change to one of these factors I recalculate the results in the underlying data table and the data is updated in the wingrid. I am displaying a summary dollar total for each category and sub category and then a final grand total at the bottom of the gird.

I have been receiving complaints from the users that sometimes the sum of the sub totals and the grand total do not add up to the same value. Of course when one of the users tried to show me it appeared to work just fine and just wrote it off as user error. As if it meant anything I tried to explain to the user that the grid control automatically calculates the sub total and total values so I doubted very much that they would not match. But today I just saw it happen with my own eyes where a user updated the mark up percentage on an estimate and the subtotal and grand total did not add up. If I'm not mistaken the group by totals did not update, but the grand total updated and was correct.

In my last post I had a situation where the group by column was not displaying correctly using an ADO column with an expression as the source. I had to use the .Bands(0).SortedColumns.RefreshSort(True) method on each grid every time I added a new record for the grid to display correct. Using the same technique to get around that problem I am able to get the grid to correctly update and the subtotals and grand totals add up correctly.

As you might imagine this whole thing was a big surprise to me. I no longer feel comfortable assuming the wingrid is going to display the correct group by summary values unless I manually kick the grid every time something changes. I don't know if this has anything do with the problem I discussed in my last post, but it seems very coincidental. The groups in a wingrid don't appear to always update when the underlying data changes.

I'm running release v9.1.2009.2029.

Parents
No Data
Reply
  • 105
    Suggested Answer
    posted

    I know this question is a little stale but I came across a similar problem and I have a solution that worked for me. The root problem here is that Group By summaries are not updating when the underlying data changes. This is because the grid is not getting notified when the data changed. Make sure the objects in your data source are implementing INotifyPropertyChanged. I always tend to implement INotifyPropertyChanging and INotifyPropertyChanged in any class that will be used with data binding.

    using System.ComponentModel;
     
    namespace Example.Models.View
    {
    
        public class ViewModelINotifyPropertyChangingINotifyPropertyChanged
        {
            private bool _excluded;
            public bool Excluded
            {
                get { return _excluded; }
                set
                {
                    OnPropertyChanging("Excluded");
                    _excluded = value;
                    OnPropertyChanged("Excluded");
                }
            }
     
            private string _value;
            public string Value
            {
                get { return _value; }
                set
                {
                    OnPropertyChanging("Value");
                    _value = value;
                    OnPropertyChanged("Value");
                }
            }
     
            public event PropertyChangingEventHandler PropertyChanging;
            public event PropertyChangedEventHandler PropertyChanged;
     
            protected void OnPropertyChanging(string propertyName)
            {
                if (PropertyChanging!=null)
                    PropertyChanging(thisnew PropertyChangingEventArgs(propertyName));
            }
            protected void OnPropertyChanged(string propertyName)
            {
                if(PropertyChanged!=null)
                    PropertyChanged(thisnew PropertyChangedEventArgs(propertyName));
            }
        }
    }
Children
No Data