Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Report Control
  New Posts New Posts RSS Feed - Subtotal in Xtreme Report?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Subtotal in Xtreme Report?

 Post Reply Post Reply
Author
Message
exycomm View Drop Down
Newbie
Newbie


Joined: 27 January 2006
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote exycomm Quote  Post ReplyReply Direct Link To This Post Topic: Subtotal in Xtreme Report?
    Posted: 27 January 2006 at 9:08am

Hi

How can make subtotals with this control?

thanks!

Back to Top
sserge View Drop Down
Moderator Group
Moderator Group


Joined: 01 December 2004
Status: Offline
Points: 1297
Post Options Post Options   Thanks (0) Thanks(0)   Quote sserge Quote  Post ReplyReply Direct Link To This Post Posted: 28 January 2006 at 11:35am
Hi,

With the standard sample application, you can calculate and show subtotals for (for example) Price column with the following piece of code. Please note that you should add Price column onto "Group By" field to enable grouping.

int nCount = GetReportCtrl().GetRows()->GetCount();
for (int i = nCount - 1; i >= 0; i--)
{
     CXTPReportRow* pRow = GetReportCtrl().GetRows()->GetAt(i);
     if (pRow->IsGroupRow())
     {
           // calculate subtotals
           double dSubtotal = 0;
           CXTPReportRows* pChildren = pRow->GetChilds();
           for (int j = pChildren->GetCount() - 1; j >= 0; j--)
           {
                CXTPReportRow* pChild = pChildren->GetAt(j);
                CMessageRecordItemPrice* pItem = DYNAMIC_DOWNCAST(CMessageRecordItemPrice, pChild->GetRecord()->GetItem(COLUMN_PRICE));
                dSubtotal += pItem->GetValue();
           }
          
           // set caption
           CXTPReportGroupRow* pGroupRow = (CXTPReportGroupRow*)pRow;
           CString strSubtotal;
           strSubtotal.Format(_T("(Subtotal: %f)"), dSubtotal);
           pGroupRow->SetCaption(pGroupRow->GetCaption() + strSubtotal);
     }
}


--
WBR,
Serge
Back to Top
Warren View Drop Down
Groupie
Groupie
Avatar

Joined: 23 February 2005
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote Warren Quote  Post ReplyReply Direct Link To This Post Posted: 20 February 2006 at 9:48am
Serge,

I understand the posted code, but where do you suggest is the most appropriate place to add this an application?

Should I derive from the report control, and add it to the end of an overrriden virtual void Populate()
Back to Top
sserge View Drop Down
Moderator Group
Moderator Group


Joined: 01 December 2004
Status: Offline
Points: 1297
Post Options Post Options   Thanks (0) Thanks(0)   Quote sserge Quote  Post ReplyReply Direct Link To This Post Posted: 20 February 2006 at 11:55am
Hi Warren,

Of course it depends on your needs, but if you need subtotals to be always properly calculated, it would be a best solution... For example, after drag-n-drop to/from group area it would be the only way to have group row captions automatically updated.

--
WBR,
Serge
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.219 seconds.