listview中的viewstyle属性为vsreport,columnclick属性为true,我想在这个事件中(listview1columnclick(sender:tobject;columnclick:tlistcolumn))进行排序,怎么写这里的代码啊?
解决方案 »
- 叫号系统中的端口连接
- 急问~~~~如何删除ACCESS表中不是今年的记录?
- 请教!service application 运行大约10秒就自己退出的问题.
- 帐套
- 有没有修改本机IP地址、DNS、网关、掩码的API函数,其它方法也可
- 关于鼠标钩子的问题
- @@@@@怎么定时执行存储过程?或者有没有按时间触发的触发器?@@@@@
- 合作开发项目招聘人员
- 关于Windows消息的若干疑问?
- 我打算以后到外资性质的电脑公司去工作,我应该重点学习VC,还是Delphi,还是C++Builder?
- How to hide certain colomn in listview?
- 【TreeView+ListView显示文件】,在线等待,请指教。一定给分!
Column: TListColumn);
begin
ColumntoSort:=column.Index;
(Sender as TCustomListView).AlphaSort;
end;procedure TFra_Change.LvSourceCompare(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;
begin
if ColumnIndex = 0 then
Result := CompareText(Item1.Caption,Item2.Caption);
else
if Item1.SubItems[ColumnIndex-1] <= Item2.SubItems[ColumnIndex-1]
then Result := -1
else Result := 1;
end;使用
procedure TSySortListView.ColumnClick(Sender: TObject; Column: TListColumn);
begin
CustomSort(@SortByString,Column.Index);
end;
ColumnToSort := Column.Index;
(Sender as TCustomListView).AlphaSort;
end;
Delphi 帮助里有例子,
在你的单元接口段的private下声明:
columntosort:integer;
isascsort:boolean;在ListView的ColumnClick事件里给columntosort赋值(被单击列的索引号),调用AlphaSort:
procedure TForm1.ListView1ColumnClick(Sender: TObject;
Column: TListColumn);
begin
isascsort:=not isascsort;
columntosort:=column.Index;
(sender as tcustomlistview).AlphaSort;
end;然后在ListView的Compare事件里写排序代码:procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer; var Compare: Integer);
var
xx:integer;
begin
if columntosort=0 then//按标题列排序;
if isascsort then
compare:=comparetext(item1.Caption,item2.Caption)
else
compare:=comparetext(item2.Caption,item1.Caption)
else//按SubItems排序
begin
xx:=columntosort-1;
if isascsort then
compare:=comparetext(item1.SubItems[xx],item2.SubItems[xx])
else
compare:=comparetext(item2.SubItems[xx],item1.SubItems[xx]);
end;
end;以上须注意排序原理,相应函数可查DELPHI帮助.