Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Controls
  New Posts New Posts RSS Feed - CXTPListCtrl / Can't have more than one and sort
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTPListCtrl / Can't have more than one and sort

 Post Reply Post Reply
Author
Message
rhfritz View Drop Down
Groupie
Groupie


Joined: 19 September 2014
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote rhfritz Quote  Post ReplyReply Direct Link To This Post Topic: CXTPListCtrl / Can't have more than one and sort
    Posted: 16 November 2017 at 3:45pm
There's a bug in XTP that is reproducible using ListCtrl_vc150 example code.  The platform is Win10 Enterprise.  Visual Studio 2017.  Xtreme ToolkitPro v18.0.1.
I've attached a screen snapshot of the problem, which is that if you have more than one CXTPListCtrl on a window, the OnNotify event does not let you differentiate which one you attempted to sort.  


Note that in the screen snapshot of the breakpoint after the if (pHDNotify->hdr.code == HDN_ITEMCLICKA ...), both wParam and pHDNotify->hdr.idFrom are zero.    We should be able to select based on either wParam or pHDNotify->hdr.idFrom to determine the origin of the message.  So the only reason the ListCtrl_vc150 example code works is that there's only one control on the dialog that could generate HDN_ITEMCLICKA.
The work around is that when the list control of interest is getting focus and the column-header is clicked, both wParam and pHDNotify->hdr.idFrom are valid, but pHDNotify->hdr.code is not HDN_ITEMCLICKA.  So by trapping the idFrom, we can determine which list control generated the event.
Here is the work around code that fixes the example:

void CListCtrlDlg::SortColumn(CXTPListCtrl *pListCtrl, int iCol, bool bAsc)
{
 m_bAscending = bAsc;  // each list control needs a unique instance
 m_nSortedCol = iCol;  // each list control needs a unique instance
 // set sort image for header and sort column.
 pListCtrl->SetSortImage(m_nSortedCol, m_bAscending);
 CXTPSortClass csc(pListCtrl, m_nSortedCol);
 csc.Sort(m_bAscending, xtpSortString);
}
BOOL CListCtrlDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
 HD_NOTIFY *pHDNotify = (HD_NOTIFY*)lParam;
#pragma region XTP_NOTIFY_BUG
 // There's a bug in XTP.  The OnNotify events received *just prior* to pHDNotify->hdr.code == HDN_ITEMCLICKA
 // have the wParam and idFrom set to the proper control.   But at the time of the HDN_ITEMCLICKA, both are always zero.
 // So we save the idFrom and use it instead.
 static UINT idFrom = 0;
 if (wParam && wParam == pHDNotify->hdr.idFrom)
  idFrom = pHDNotify->hdr.idFrom;
#pragma endregion
 if (pHDNotify->hdr.code == HDN_ITEMCLICKA ||
  pHDNotify->hdr.code == HDN_ITEMCLICKW)
 {
  switch (idFrom)
  {
   case IDC_LIST_CTRL:
    if (pHDNotify->iItem == m_nSortedCol)
     SortColumn(&m_listCtrl, pHDNotify->iItem, !m_bAscending);
    else
     SortColumn(&m_listCtrl, pHDNotify->iItem, BoolType(m_header.GetAscending()));
    break;
   case IDC_LIST_CTRL2:
    if (pHDNotify->iItem == m_nSortedCol)
     SortColumn(&m_listCtrl2, pHDNotify->iItem, !m_bAscending);
    else
     SortColumn(&m_listCtrl2, pHDNotify->iItem, BoolType(m_header.GetAscending()));
    break;
  }
 }
 return CXTPResizeDialog::OnNotify(wParam, lParam, pResult);
}


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.