***report状态的Listview,点击每个列都可排序,如何实现?***

ajun21cn 2002-07-16 02:52:09
有无加强的控件,最好能象windows上的那样,点一次升序,第二次降序。



...全文
32 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccnh 2002-07-20
  • 打赏
  • 举报
回复
我正在用的。

function CustomSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
implementation//之前定义上面这句

procedure TForm1.ListView1ColumnClick(Sender: TObject;
Column: TListColumn);
begin
ListData.CustomSort(@CustomSortProc, Column.Index);
end;

function CustomSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
begin
if ParamSort>0 then
Result := CompareText(Item1.SubItems.Strings[ParamSort-1],Item2.SubItems.Strings[ParamSort-1])
else
Result := CompareText(Item1.Caption,Item2.Caption);
end;
netlib 2002-07-20
  • 打赏
  • 举报
回复
var ColumnToSort: Integer;

The OnColumnClick event handler sets the global variable to indicate the column to sort and calls AlphaSort:

procedure TForm1.ListView1ColumnClick(Sender: TObject; Column: TListColumn);

begin
ColumnToSort := Column.Index;
(Sender as TCustomListView).AlphaSort;
end;


The OnCompare event handler causes the list view to sort on the selected column:

procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer);
var
ix: Integer;
begin
if ColumnToSort = 0 then
Compare := CompareText(Item1.Caption,Item2.Caption)
else begin
ix := ColumnToSort - 1;
Compare := CompareText(Item1.SubItems[ix],Item2.SubItems[ix]);
end;

end;
byrrj 2002-07-20
  • 打赏
  • 举报
回复
自己写代码完成 ,难难
ehom 2002-07-20
  • 打赏
  • 举报
回复
在ListViewColumnClick,ListViewCompare 事件中添加代码!
ehom 2002-07-20
  • 打赏
  • 举报
回复
在ListView1ColumnClick,ListView1Compare 事件中添加代码!
ehom 2002-07-20
  • 打赏
  • 举报
回复
只可以对第一项进行排序,如果要使用后面的项目进行排序只能在ListViewColumnClick,ListViewCompare 事件中添加代码!
ajun21cn 2002-07-20
  • 打赏
  • 举报
回复
???
ajun21cn 2002-07-16
  • 打赏
  • 举报
回复
???

5,392

社区成员

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

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