Gridview summary row conditional sum

8 posts, 0 answers
  1. Mitul
    Mitul avatar
    4 posts
    Member since:
    Feb 2012

    Posted 21 Feb 2012 Link to this post

    I am still using a trial version of GridView to get an idea how powerful the control is. So, far everything is going good except I have no idea how to handle following situation.
    The data is as follow

    stock1 B 15
    stock1 S 45
    stock1 B 67
    stock1 S  2

    Where S-Sell and B-Buy. While grouping on column 1 (stock1) I need to display the position in stock1. But to do that while summing up the result the sell qty should be considered negative. How can I customize this sum operation?

    Mitul
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 21 Feb 2012 Link to this post

    Hello,

    If you have a look at this help topic on Summary Rows and see the last example, this shows how to customise the summary row.
    Hope that helps
    Richard
  3. Mitul
    Mitul avatar
    4 posts
    Member since:
    Feb 2012

    Posted 21 Feb 2012 Link to this post

    Thanks for the prompt response.

    I already tried that before posting the question. Here is the code that I am using. I have made one modification though where it checks whether the side has valid value or not. Although all of my rows in the gridview has side and filledqty populated after groping it throws exception if I don't put the null checking condition.


    By the way the null condition occurs when I group the data by dragging exchange and product.

     public class CustomSummaryItem : GridViewSummaryItem
        {
            public CustomSummaryItem()
                : base()
            { }

            public override object Evaluate(IHierarchicalRow row)
            {
                int totalPos = 0;
                foreach (GridViewRowInfo childRow in row.ChildRows)
                {
                   object objSide= childRow.Cells["Side"].Value;
                   if (objSide != null) /// if I don' know why but without this condition it throws null exception while retrieving FIlledQty.
                   {
                       if ((string)objSide == "B")
                       {
                           totalPos += (int)childRow.Cells["FilledQty"].Value;
                       }
                       else
                       {
                           totalPos -= (int)childRow.Cells["FilledQty"].Value;
                       }
                   }
                }
                return totalPos;
            }
        }
  4. Mitul
    Mitul avatar
    4 posts
    Member since:
    Feb 2012

    Posted 23 Feb 2012 Link to this post

    The solution which worked for me is the following one. Basically what happens is when you remove/add a group childrows might have two types of rows one with data and one with of type GridViewGroupRowInfo type which  does not have data but only the group total.


    The only problem now is I have a summary row on top which shows the total correctly but as soon as the view is grouped and any of the items gets updated the main summary row total goes to 0.


      public class CustomSummaryItem : GridViewSummaryItem
        {
            public CustomSummaryItem()
                : base()
            { }

            public override object Evaluate(IHierarchicalRow row)
            {
                int totalPos = 0;
                foreach (GridViewRowInfo childRow in row.ChildRows)
                {
                    if ((childRow is GridViewGroupRowInfo) == false)
                    {

                        object objSide = childRow.Cells["Side"].Value;
                        string type = Convert.ToString(childRow.Cells["ProdType"].Value);
        
                            if (type == "FUTURE")
                            {
                                if ((string)objSide == "B")
                                {
                                    totalPos += (int)childRow.Cells["FilledQty"].Value;
                                }
                                else
                                {
                                    totalPos -= (int)childRow.Cells["FilledQty"].Value;
                                }
                            }
                        }
        
                }
                return totalPos;
            }
        }

    Thanks,

    Mitul Patel
  5. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 24 Feb 2012 Link to this post

    Hi Mitul,

    Please open a new support ticket and send us a sample project that demonstrates the described behavior with some part of your data and grouping settings applied to RadGridView. This will allow us to investigate the issue locally. 

    Thank you for yout time and cooperation.

    Kind regards,
    Julian Benkov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  6. Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 24 Feb 2012 Link to this post

    Hi Mitul,

    Please open a new support ticket and send us a sample project that demonstrates the described behavior with some part of your data and grouping settings applied to RadGridView. This will allow us to investigate the issue locally. 

    Thank you for yout time and cooperation.

    Kind regards,
    Nikolay
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  7. Mitul
    Mitul avatar
    4 posts
    Member since:
    Feb 2012

    Posted 24 Feb 2012 Link to this post

    Thanks for the response admins. I am sorry but I won't be able to share the code of the proprietary trading application. I have explained the grouping code that I am using over here. I have also posted few other issues in that ticket.

    Thanks,

    Mitul Patel
  8. Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 29 Feb 2012 Link to this post

    Hi Mitul,

    You can find our answer in the other thread that you have opened. Please note that it has been converted to a support thread and you will not be able to find it as a forum thread. You can find it in your account after you log in.

    Kind regards,
    Nikolay
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top