Veröffentlicht 25. März 200421 j Hallo Leutz, VS.Net 7.0.1 ich habe mal wieder ein Problem. In meiner ListCtrl funkt das Sortieren nicht. Ich bekomme in der CALLBACK Funktion kein LPARAM lParam1 und LPARAM lParam2. Was mach ich falsch??? In der MSDN stehts genau so (fast). void CMyList::OnLvnColumnclickListdelta(NMHDR *pNMHDR, LRESULT *pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; *pResult = 0; SortInfo.pListCtrl = &m_ctrlListMsiDelta; SortInfo.iList = pNMListView->iSubItem; if(SortInfo.bSortDirection == true) SortInfo.bSortDirection = false; else SortInfo.bSortDirection = true; m_ctrlListMsiDelta.SortItems(CompareDelta, (DWORD)&SortInfo); for(int i = 0;i < m_ctrlListMsiDelta.GetItemCount(); i++) { m_ctrlListMsiDelta.SetItemData(i,i); } } int CALLBACK CompareDelta(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { STRUCKT_SORT_INFO *pSortInfo = reinterpret_cast<STRUCKT_SORT_INFO*>(lParamSort); //CString test = pSortInfo->pListCtrl->GetItemText(0,0); CString strItem1 = pSortInfo->pListCtrl->GetItemText(lParam1, pSortInfo->iList); CString strItem2 = pSortInfo->pListCtrl->GetItemText(lParam2, pSortInfo->iList); int iResult = 0; if(pSortInfo->iList == 0) { int a = atoi(strItem1); int b = atoi(strItem2); if(pSortInfo->bSortDirection == true) { if( a < b ) iResult = 1; else iResult = -1; }else if( a > b ) iResult = 1; else iResult = -1; } else { iResult = strcmp(strItem1, strItem2); if(pSortInfo->bSortDirection == true) iResult *= -1; } return iResult; }
25. März 200421 j Was in der MSDN Library nicht so explizit drin steht, ist, dass in lParam1 und lParam2 nicht die Indices der zu vergleichenden Einträge stehen, sondern die Werte, die den Einträgen mit SetItemData zugewiesen wurden. Wenn du das nie gemacht hast, werden beide Werte immer 0 sein.
26. März 200421 j THX aber das ist es nicht gewesen. In meiner Class war was anderes Faul. Danke noch mal.
Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.