MFC列表控件排序问题
以第一列为根据的排列intCALLBACKCShowLes::CompareFunc(LPARAMlParam1,LPARAMlParam2,LPARAMlParamSo...
以第一列为根据的排列
int CALLBACK CShowLes::CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
CString strItem1 = pListCtrl->GetItemText(lParam1, 0);
CString strItem2 = pListCtrl->GetItemText(lParam2, 0);
LPCTSTR s1=(LPCTSTR)strItem1;
LPCTSTR s2=(LPCTSTR)strItem2;
int n1=atoi(s1);
int n2=atoi(s2);
if (n1>n2)
return -1;
else
return 1;
}
void CShowLes::OnColumnclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
m_List.SortItems( CompareFunc, (DWORD)&m_List);
*pResult = 0;
}
但是如上方法只能排序前两个,数据三个或者三个以上就不行了,请问如何解决?
如果这个不行还有什么排序方法吗? 展开
int CALLBACK CShowLes::CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
CString strItem1 = pListCtrl->GetItemText(lParam1, 0);
CString strItem2 = pListCtrl->GetItemText(lParam2, 0);
LPCTSTR s1=(LPCTSTR)strItem1;
LPCTSTR s2=(LPCTSTR)strItem2;
int n1=atoi(s1);
int n2=atoi(s2);
if (n1>n2)
return -1;
else
return 1;
}
void CShowLes::OnColumnclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
m_List.SortItems( CompareFunc, (DWORD)&m_List);
*pResult = 0;
}
但是如上方法只能排序前两个,数据三个或者三个以上就不行了,请问如何解决?
如果这个不行还有什么排序方法吗? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询