怎样给;listview按数字大小排序?

hjp0214 2002-12-01 09:25:57
设置ListView的

SortType属性为stBoth。然后在OnCompare事件中输入比较大小的代码。
procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2:

TListItem;
Data: Integer; var Compare: Integer);
var m, n :integer;
begin
m := StrToInt(Item1.Caption);
n := StrToInt(Item2.Caption);
Compare := m - n;
end;

但listciew就是没有排序呢?

...全文
191 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
pidi 2002-12-01
  • 打赏
  • 举报
回复
The following code orders a list view in reverse alphabetical order on the click of a button. The callback function CustomSortProc calls the global CompareText function and negates its return value.

function CustomSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;//自己写回调函数。
begin
Result := -CompareText(Item1.Caption,Item2.Caption);
//你可改成按数字大小排序
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ListView1.CustomSort(@CustomSortProc, 0);
end;

你看看帮助,很详细的

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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