Print Page | Close Window

ReportControl expands groups on populate

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=1689
Printed Date: 02 May 2024 at 3:49am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: ReportControl expands groups on populate
Posted By: AndersH
Subject: ReportControl expands groups on populate
Date 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?




Replies:
Posted By: sserge
Date 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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net