Print Page | Close Window

CXTPListCtrl / Can't have more than one and sort

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Controls
Forum Description: Topics Related to Codejock Controls
URL: http://forum.codejock.com/forum_posts.asp?TID=23490
Printed Date: 26 April 2024 at 3:02pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTPListCtrl / Can't have more than one and sort
Posted By: rhfritz
Subject: CXTPListCtrl / Can't have more than one and sort
Date 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);
}





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