Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - ReportControl expands groups on populate
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

ReportControl expands groups on populate

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


Joined: 21 January 2005
Location: Norway
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndersH Quote  Post ReplyReply Direct Link To This Post Topic: ReportControl expands groups on populate
    Posted: 21 January 2005 at 4:41am

We have develepoed a report control based task list which is automatically refreshed at regular intervals. If the user has applied custom grouping and collapsed some of the groups all the groups are expanded the next time populate is called. The behaviour can very easily be seen in the ReportControl sample: group by something and collapse a few groups. Double-click a bold line to set its state to read - all groups are expanded.

Does anyone have any idea on how to avoid this?

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: 24 March 2006 at 3:16pm
Hi,

Please note that after repopulating the control, all rows, including group rows, have renewed to another objects. That's why all theirs properties, including collapsed state are lost.

However, of course the solution exists. For example, you can override Populate() method for your control, or just add "before" and "after" Populate blocks of code, where you'll save Rows state before Populating, and restore it after.

For example on how it could be accomplished see below:

    {
        // Save previous Collapsed state
        CXTPReportRecords recs;       
        CStringArray arGroups;       
        int nRowsCount = GetReportCtrl().GetRows()->GetCount();
        int nRow = 0;
        for (nRow = 0; nRow < nRowsCount; nRow++)
        {
            CXTPReportRow* pRow = GetReportCtrl().GetRows()->GetAt(nRow);

            // save possible collapsed "Tree" rows
            if (pRow && pRow->HasChildren() && !pRow->IsGroupRow() && !pRow->IsExpanded())
            {
                recs.Add(pRow->GetRecord());
            }

            // Save possible collapsed Group rows
            if (pRow && pRow->IsGroupRow() && !pRow->IsExpanded())
            {
                CXTPReportGroupRow* pGRow = (CXTPReportGroupRow*)pRow;
                arGroups.Add(pGRow->GetCaption());
            }
        }

        // Call base Populate()
        GetReportCtrl().Populate();

        // Restore Collapsed state
        nRowsCount = GetReportCtrl().GetRows()->GetCount();
        for (nRow = 0; nRow < nRowsCount; nRow++)
        {
            CXTPReportRow* pRow = GetReportCtrl().GetRows()->GetAt(nRow);
            if (pRow && pRow->HasChildren())
            {
                // Check for group row
                if (pRow->IsGroupRow())
                {
                    CXTPReportGroupRow* pGRow = (CXTPReportGroupRow*)pRow;
                    for (int i = 0; i < arGroups.GetSize(); i++)
                    {
                        if (!pGRow->GetCaption().Compare(arGroups.GetAt(i)))
                        {
                            pGRow->SetExpanded(FALSE);
                            break;
                        }
                    }
                }
                else
                // Check Tree rows
                {
                    for (int i = 0; i < recs.GetCount(); i++)
                    {
                        if (pRow->GetRecord() == recs.GetAt(i))
                        {
                            pRow->SetExpanded(FALSE);
                            break;
                        }
                    }
                }
            }
        }
    }


--
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.141 seconds.