我想请问当我点击listview上面每一列的标题时可以实现排序的功能
请问这样的功能是怎么实现的 在listview里面可以实现吗?
哪位高手会的请指点
小弟这里感谢了?
请问这样的功能是怎么实现的 在listview里面可以实现吗?
哪位高手会的请指点
小弟这里感谢了?
解决方案 »
- 在delphi中如何向oracle中存入照片?
- 【国庆】 2006年应届毕业生都进来坐坐,谈谈近况 【中秋】
- teeChart 如何实现初始化状态
- 求助各位大侠:如何将memo中的各行列内容按照次序加入到ComboBox下拉选项框中??还有,如何从ini文件中读取相应数据到memo及ComboBox中
- IC卡开发,在DELPHI中如何直接调用WINDOWS API(ScardTransmit)?
- 谁有珍藏的PASCAL基础的PDF?
- 我需要在内存中做一个链表作为文件的缓冲,请问有什么方法可以动态的得到内存的地址。
- 请教 怎么把dbgrideh里查询显示的多条记录修改后,做为新的数据保存到sql2000里
- 急问:这个如何实现?
- 请问如何判断一个TForm对象是否已经存在?
- 问题
- 请问一下!!!!
在你的单元接口段的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;
你去试试看能不能符合你的要求。
Data: Integer; var Compare: Integer);
var
ix : Integer;
begin if cancompare then exit;
if not SortStyle Then
if ColumnToSort = 0 then
Compare := CompareText(Item1.Caption,Item2.Caption)
else begin
ix := ColumnToSort - 1;
Compare := CompareText(Item1.SubItems[ix],Item2.SubItems[ix]);
end
Else
if ColumnToSort = 0 then
Compare := CompareText(Item2.Caption,Item1.Caption)
else begin
ix := ColumnToSort - 1;
Compare := CompareText(Item2.SubItems[ix],Item1.SubItems[ix]);
end;end;给分