Sorting data in CListCtrl columns...
-
Hi, I need to sort data in List Ctrl (report view) when user clicks on any of the column headers. Ascending and descending on alternate clicks. Plz help.
Hi, try to look throw this functions void CMListCtrl::DoSort() { SortItems((PFNLVCOMPARE)MySort,(LPARAM)this); } BEGIN_MESSAGE_MAP(CMListCtrl, CListCtrl) ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnclick) END_MESSAGE_MAP() void CMListCtrl::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult) { NMLISTVIEW* pNMListView = (NMLISTVIEW*)pNMHDR; int iColumn = pNMListView->iSubItem + 1; int iColumnLast = m_iSortedCol; if (iColumn == abs(iColumnLast)) { iColumn = -iColumnLast; } m_iSortedCol = iColumn; DoSort(); } /* The comparison function must return a negative value if the first item should precede the second, a positive value if the first item should follow the second, or zero if the two items are equivalent.*/ static int CALLBACK CMListCtrl::MySort(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { CMListCtrl* _this = (CMListCtrl*)lParamSort; CFileItem* pFIOne = (CFileItem *)lParam1; // was added using Insert CFileItem* pFITwo = (CFileItem *)lParam2; // was added using Insert return 0; }