|
-
June 22nd, 2007, 03:25 AM
#1
[RESOLVED] Strange CListCtrl Sort Behaviour
Hi There!
First of all, thank you all for your participation i this board! I am watching it frequently and it has helped me many many times by now!
This is the first time I encounter a problem, to wich I can not find a solution here!
I am trying to sort a CListCtrl. The Control has the colums "Last Name","First Name", "Date of Birth" and "ID" wich is a unique number.
(if Patients are displayed, there is also the possibility that the List contains Measurements, but that's not the topic right now! Trying to sort the Patients first!)
If i sort the List for "First Name" it works once. Second time I do it, the List gets back to the prev. sort order! If I dont sort for First name the second time, but for Patients ID, everything is in a chaos (no sorting to recognize!).
Here is my Callback Function:
Code:
void CAngEDlg::OnLvnColumnclickListe(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
m_ColToSort=pNMLV->iSubItem; //Store the Column To Sort in Member Var.
m_pListe->SortItems((PFNLVCOMPARE)MyCompareProc, (LPARAM) m_pListe);//Try to Sort
*pResult = 0;
}
//Sortier-Callback
int CALLBACK CAngEDlg::MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
CAngEDlg* main;
// lParamSort contains a pointer to the list view control.
CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
main=(CAngEDlg*)pListCtrl->GetParent(); //Get Parent to access members
if(main->m_bPatientsListed) //If Patients are displayed, do the following
{
CString strItem1 = pListCtrl->GetItemText(lParam1, main->m_ColToSort);
CString strItem2 = pListCtrl->GetItemText(lParam2, main->m_ColToSort);
if( main->m_ColToSort==0 || main->m_ColToSort==1) //Sort for First or Second Name
return strcmp( strItem1,strItem2);
if( main->m_ColToSort==3) // Sort for unique ID
{
int aa;
int b;
aa = atoi (strItem1);
b= atoi (strItem2);
if(aa<b) return 1;
else -1;
}
//No Sorting for Birthday yet!
}
else //If Measurements are displayed, do nothing by now
{
}
return 0;
}
Any Ideas??
Thank's in advance
Marc
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|