请问: LISTVIEW中怎样进行排序?

vc_boy 2000-12-14 10:12:00
想通过单击列头后按此列进行排序。
...全文
178 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
prog_st 2001-09-03
  • 打赏
  • 举报
回复
若需要,给例程。Email
swordbroken 2001-09-03
  • 打赏
  • 举报
回复
CListCtrl::SortItems
BOOL SortItems( PFNLVCOMPARE pfnCompare, DWORD dwData );

Return Value

Nonzero if successful; otherwise zero.

Parameters

pfnCompare

Address of the application-defined comparison function. The comparison function is called during the sort operation each time the relative order of two list items needs to be compared. The comparison function must be either a static member of a class or a stand alone function that is not a member of any class.

dwData

Application-defined value that is passed to the comparison function.

Remarks

Sorts list view items using an application-defined comparison function. The index of each item changes to reflect the new sequence.

The comparison function has the following form:

int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2,
LPARAM lParamSort);

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.

The lParam1 and lParam2 parameters specify the item data for the two items being compared. The lParamSort parameter is the same as the dwData value.

Example

// Sort the item in reverse alphabetical order.
static int CALLBACK
MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
// lParamSort contains a pointer to the list view control.
// The lParam of an item is just its index.
CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
CString strItem1 = pListCtrl->GetItemText(lParam1, 0);
CString strItem2 = pListCtrl->GetItemText(lParam2, 0);

return strcmp(strItem2, strItem1);
}

void snip_CListCtrl_SortItems()
{
// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;

// Sort the list view items using my callback procedure.
pmyListCtrl->SortItems(MyCompareProc, (LPARAM) pmyListCtrl);
}

skt642 2001-05-31
  • 打赏
  • 举报
回复
39052关注!
sun2000 2000-12-15
  • 打赏
  • 举报
回复
这个问题讨论的次数太多了,查一下ListView或者ListCtrl就有
breath 2000-12-15
  • 打赏
  • 举报
回复
csdn上就有很多这样的例子
有外部排序的
有继承的
你找找看
happylaodu 2000-12-15
  • 打赏
  • 举报
回复
建议最好按数字排序,要是按字符串排序才烦呢,反正我是不想做。
vc_boy 2000-12-14
  • 打赏
  • 举报
回复
to patrickgamp:
谢谢,但是SORTITEM的用法我不太了解。
PatrickGamp 2000-12-14
  • 打赏
  • 举报
回复
SortItem
zzh 2000-12-14
  • 打赏
  • 举报
回复
这里面使用它的SortItems函数进行排序,你可以通过响应单击列头消息进行处理,当点击列头时,调用一个自己定义的排序函数,同时传递一个参数,真正排序的工作是由自己写的函数来实现的。SortItems()函数的第一个参数为你定义函数的指针

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧