Print Page | Close Window

Columns Expand/Collapse not working

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Report Control
Forum Description: Topics Related to Codejock Report Control
URL: http://forum.codejock.com/forum_posts.asp?TID=20417
Printed Date: 13 June 2025 at 4:59pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Columns Expand/Collapse not working
Posted By: Sergio
Subject: Columns Expand/Collapse not working
Date Posted: 11 December 2012 at 6:08am
Hello,

There is a bug in code, columns expand/collapse doesn't work.


Your code (Codejock MFC TookKit Pro version 15.2.1):

void CXTPReportColumn::SetExpanded(BOOL bExpanded)
{
           m_bExpanded = bExpanded;
          int nCnt = m_pColumns->GetCount();
          int iN = GetNextVisualBlock();
          int iVs = GetVisibleIndex();
          CXTPReportColumn* pCol = NULL;
          for (int iC = 0; iC < nCnt; iC++)
          {
                    pCol = m_pColumns->GetAt(nCnt - iC - 1);
                    if (pCol)
                    {
                              if (bExpanded)
                              {
                                        int iVc = pCol->GetVisibleIndex();
                                        if (iVc == -1) continue;
                                        if (iN > 0 && iVc > iVs && iVc <= iVs + iN)
                                                  pCol->SetVisible(FALSE);
                                        else if (iN < 0 && iVc < iVs && iVc >= iVs + iN)
                                                  pCol->SetVisible(FALSE);
                              }
                              else
                              {
                                        int iVc = pCol->GetOldVisibleIndex();
                                        if (iVc == -1) continue;
                                        if (iN > 0 && iVc > iVs && iVc <= iVs + iN)
                                                  pCol->SetVisible(TRUE);
                                        //else if (iN < 0 && iVc <= iVs + 1 && iVc >= iVs + iN)
                                        else if (iN < 0 && iVc <= iVs + 2 && iVc >= iVs + iN)
                                                  pCol->SetVisible(TRUE);
                              }
                    }
          }
}


My fix:

int CMyXTPReportColumn::SetExpanded(BOOL bExpanded)
{
          // Fixes a bug in Codejock version 15.2.1 - CXTPReportColumn::SetExpanded(...)
          m_bExpanded = bExpanded;
          CXTPReportControl* pControl = GetControl();
          if (pControl)
          {
                    int nNextVisualBlock = GetNextVisualBlock();
                    if (nNextVisualBlock != 0)
                    {
                              int nItemIndex = GetItemIndex();
                              int nStart;
                              int nEnd;

                              if (nNextVisualBlock < 0)
                              {
                                        nStart = nItemIndex + nNextVisualBlock;
                                        nEnd = nItemIndex;
                              }
                              else
                              {
                                        nStart = nItemIndex + 1;
                                        nEnd = nItemIndex + nNextVisualBlock + 1;
                              }

                              CXTPReportColumn* pColumnExp;
                              for (int i=nItemIndex + nNextVisualBlock; i < nItemIndex; i++)
                              {
                                        pColumnExp = pControl->FFindColumn(i); // Find column by internal index instead of position
                                        if (pColumnExp)
                                                  pColumnExp->SetVisible(bExpanded);
                              }
                    }

                    pControl->AdjustLayout();
                    pControl->AdjustScrollBars();
          }
}


Moreover, beware of initial state of expand/collapse that isn't also correctly set. I let you do that fix by yourself.

Regards


-------------
Sergio



Replies:
Posted By: Sergio
Date Posted: 11 December 2012 at 6:17am
Please note that FFindColumn(...) is our method, it find the column by the item index rather than by the column position.

Doing so, it works also when the columns are moved!

Your code doesn't work also when columns aren't moved!

Regards


-------------
Sergio


Posted By: Sergio
Date Posted: 11 December 2012 at 6:32am
I've just updated my post with some fixes...



-------------
Sergio


Posted By: Algae
Date Posted: 25 November 2013 at 3:19pm
Sergio -

Thanks for the fix.

It looks cleaner than the CJ material. For V. 16.2.3 I found it unnecessary though.

A couple things, relevant to 16.2.3:

1. Shouldn't function be void?
2. pColumnExp = GetColumns()->Find(i); // replace FFind.




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