CMainFrame* cFrm = (CMainFrame*)::AfxGetMainWnd();
CString strValue1 = cFrm->mcListCtrl.GetItemText(int(lParam1),cFrm->Column);
CString strValue2 = cFrm->mcListCtrl.GetItemText(int(lParam2),cFrm->Column);
int a = atoi(strValue1);
int b = atoi(strValue2);
if( a==b ) return 0;
return a>b? 1: -1;我跟踪了排序,它得到了:703》558》400》92但是,显示的时候却变成了,703在前,400随后,然后是92,最后是558,怎么回事?
CString strValue1 = cFrm->mcListCtrl.GetItemText(int(lParam1),cFrm->Column);
CString strValue2 = cFrm->mcListCtrl.GetItemText(int(lParam2),cFrm->Column);
int a = atoi(strValue1);
int b = atoi(strValue2);
if( a==b ) return 0;
return a>b? 1: -1;我跟踪了排序,它得到了:703》558》400》92但是,显示的时候却变成了,703在前,400随后,然后是92,最后是558,怎么回事?
解决方案 »
- 高分相求纯代码实现汉字书写演示。
- 希望大家帮我看哈,搞了两天没搞出来,,谢谢
- 用ado如何判断1个字段应该用getCollect还是getChunk读数据?
- 在基于对话框应用程序中,打开新对话框时如何让它在最大化的同时使里面的控件能够按照比例自动缩放!
- 我用MoveTo,LineTo画了一个多边形,哪位高手看看该如何填充呀??
- 哪位大虾帮忙解决一下vc中工具条的显示位置问题?
- 如何取得当前的系统dsn.
- 想破脑袋的组件访问问题
- vs2010中使用MSFlexGrid的问题
- SDK程序是用什么编译器编译的?哪里有下载?
- 窗口分割后的打印问题( :(没分啦 )
- 高分求教:一个很专业的问题,小弟谢谢了。
CRect(22,42,624,121), (CWnd*)&DialogBar, IDC_LIST1);
mcListCtrl.ModifyStyleEx(0, WS_EX_CLIENTEDGE, SWP_DRAWFRAME);而且每次排序最后的结果很可能不同。
int CALLBACK ListCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
CMainFrame* cFrm = (CMainFrame*)::AfxGetMainWnd();
CString strValue1 = cFrm->mcListCtrl.GetItemText(int(lParam1),cFrm->Column);
CString strValue2 = cFrm->mcListCtrl.GetItemText(int(lParam2),cFrm->Column);
int a = atoi(strValue1);
int b = atoi(strValue2);
if( a==b ) return 0;
return a>b? 1: -1;
}
请参阅:http://www.codeproject.com/buglist/listcontrolsortitemsbug.asp#xx503965xx//******************************************
Example of CListCtrl::SortItems(...) in MSDN
By Ivor S. Sargoytchev The given example in the documentation of CListCtrl::SortItems(...) shows us exactly the WRONG way of using the function.
//******************************************int CALLBACK CSCListCtrl::CompareFunction( LPARAM lParam1, LPARAM lParam2, LPARAM lParamData )
{
CSCListCtrl* pListCtrl = (CSCListCtrl*) lParamData;LVFINDINFO pInfo1, pInfo2;
pInfo1.flags = LVFI_PARAM;
pInfo2.flags = LVFI_PARAM;
pInfo1.lParam = lParam1;
pInfo2.lParam = lParam2;
int ind1 = pListCtrl->FindItem(&pInfo1);
int ind2 = pListCtrl->FindItem(&pInfo2);
CString strItem1 = pListCtrl->GetItemText(ind1, pListCtrl->m_iSortColumn);
CString strItem2 = pListCtrl->GetItemText(ind2, pListCtrl->m_iSortColumn);return pListCtrl->m_bSortAscending ? lstrcmp( strItem1, strItem2 ) : lstrcmp( strItem2, strItem1 );
}