Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Report Control
  New Posts New Posts RSS Feed - Columns Expand/Collapse not working
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Columns Expand/Collapse not working

 Post Reply Post Reply
Author
Message
Sergio View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 September 2006
Status: Offline
Points: 216
Post Options Post Options   Thanks (1) Thanks(1)   Quote Sergio Quote  Post ReplyReply Direct Link To This Post Topic: Columns Expand/Collapse not working
    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
Back to Top
Sergio View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 September 2006
Status: Offline
Points: 216
Post Options Post Options   Thanks (0) Thanks(0)   Quote Sergio Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Sergio View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 September 2006
Status: Offline
Points: 216
Post Options Post Options   Thanks (0) Thanks(0)   Quote Sergio Quote  Post ReplyReply Direct Link To This Post Posted: 11 December 2012 at 6:32am
I've just updated my post with some fixes...

Sergio
Back to Top
Algae View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 January 2007
Location: United States
Status: Offline
Points: 217
Post Options Post Options   Thanks (0) Thanks(0)   Quote Algae Quote  Post ReplyReply Direct Link To This Post 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.

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