listview的排序功能是如何实现的?新插入的行,能自动排序吗
listview的排序功能是怎么实现的?新插入的行,能自动排序吗?
我看到有的listview,能实现这样的功能:比如有这样几列:
姓名 年龄 分数
鼠标点击“姓名“,下面的各行就会按“姓名”排序,再点一次,按“姓名”反向排序。
同理,点击一个“分数”,则会按“分数”从高到低排序,再点一下,则从低到高排序。
这个是怎么实现的?
另外:如果按某项排序后,再加入新的项目,能否自动插入到相应的位置呢?(就是根据当前排序规则应该具有的位置)。
------解决思路----------------------
加入新的项也要自动有序,这个需要自己实现,大概的流程就是拿新添加的项和原来的所有项进行比较,然后清空原来的list从新添加
------解决思路----------------------
sort 属性
"如果按某项排序后,再加入新的项目,能自动插入到相应的位置"
------解决思路----------------------
listview 的排序需要你提供一个排序回调函数
当列表需要排序时会调用你的函数, 你在函数中决定两个值的先后位置来决定顺序
无论插入数据或是修改数据, 列表都会调用你的排序函数的
------解决思路----------------------
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.
我看到有的listview,能实现这样的功能:比如有这样几列:
姓名 年龄 分数
鼠标点击“姓名“,下面的各行就会按“姓名”排序,再点一次,按“姓名”反向排序。
同理,点击一个“分数”,则会按“分数”从高到低排序,再点一下,则从低到高排序。
这个是怎么实现的?
另外:如果按某项排序后,再加入新的项目,能否自动插入到相应的位置呢?(就是根据当前排序规则应该具有的位置)。
------解决思路----------------------
加入新的项也要自动有序,这个需要自己实现,大概的流程就是拿新添加的项和原来的所有项进行比较,然后清空原来的list从新添加
------解决思路----------------------
sort 属性
"如果按某项排序后,再加入新的项目,能自动插入到相应的位置"
------解决思路----------------------
listview 的排序需要你提供一个排序回调函数
当列表需要排序时会调用你的函数, 你在函数中决定两个值的先后位置来决定顺序
无论插入数据或是修改数据, 列表都会调用你的排序函数的
------解决思路----------------------
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.