同上!
解决方案 »
- IdHttp 提交Cookie做模拟登录
- 请问大家一下..如何把两个FROM组合在一起.
- 问:串口通信中variant和olevariant的问题
- 其他语言能否用Delphi控件??
- 出差ing,现在可以上网了,散分
- 大家讨论 com 和 automate 有什么关系
- 我要恢复数据库,怎么获得这个数据库的独占权?
- Service Application里得不到关机消息么?
- 画板只能处理位图(Tbitmap)格式的图像吗?如何用Canvas处理.jpg格式的文件?解决问题后马上给分!!!
- 有关sql中count的问题!!!
- 帮我看看这个提示错误我怎么解决(动态连接库问题!!dll)!!!
- 简单问题
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;
var ColumnToSort: Integer;
然后添加ListView对象的OnColumnClick事件:
procedure TForm1.ListView1ColumnClick(Sender: TObject; Column: TListColumn);begin
ColumnToSort := Column.Index;
(Sender as TCustomListView).AlphaSort;
end;
最后添加ListView对象的OnCompare事件:
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;
在你的单元接口段的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;
刚才我去试了一下(下雨天)写的,可以排序,但是我们点某一列的时候应该出现一个上下的键诚头,就像其他的软件一样的效果,不知道listview能不能完成这样的效果
----------------
请看
http://community.csdn.net/Expert/topic/3042/3042049.xml?temp=.4693872