目前需要一个鼠标单击列头能实现排序功能的ListView控件,所以现从TListView继承生成子控件TSortListView,希望在TSortListView内部接收ColumnClick和Compare事件并实现排序。处理的代码
已经写好了(MyColumnClick和MyCompare),但不知道怎么接收对应的事件来调用我的排序处理代码。
忘高手指点一二,小弟先谢谢了。unit SortListView;interfaceuses
Windows, Messages, SysUtils, Classes, ComCtrls, Commctrl, WinSock;type
TSortListView = class(TListView)
private
IntSortCol:Integer;//当前鼠标点击排序的列
BlDesc:Boolean;//升序、降序标记
//当接收到ColumnClick事件时调用过程MyColumnClick进行处理
procedure MyColumnClick(Sender: TObject; Column: TListColumn);
//当接收到Compare事件时调用过程MyCompare进行处理
procedure MyCompare(Sender: TObject; Item1,
Item2: TListItem; Data: Integer; var Compare: Integer);
protected public published end;procedure Register;implementationprocedure TSortListView.MyColumnClick(Sender: TObject; Column: TListColumn);
begin
IntSortCol := Column.Index;
Self.AlphaSort;
BlDesc := Not BlDesc;
end;procedure TSortListView.MyCompare(Sender: TObject; Item1,
Item2: TListItem; Data: Integer; var Compare: Integer);
beginIf IntSortCol = 0 then
Compare := CompareStr (Item1.Caption, Item2.Caption)
Else
Compare := CompareStr (Item1.SubItems [IntSortCol - 1],
Item2.SubItems [IntSortCol - 1]); If(BlDesc) Then
Compare := 0-Compare;
end;
procedure Register;
begin
RegisterComponents('Win32', [TSortListView]);
end;end.
已经写好了(MyColumnClick和MyCompare),但不知道怎么接收对应的事件来调用我的排序处理代码。
忘高手指点一二,小弟先谢谢了。unit SortListView;interfaceuses
Windows, Messages, SysUtils, Classes, ComCtrls, Commctrl, WinSock;type
TSortListView = class(TListView)
private
IntSortCol:Integer;//当前鼠标点击排序的列
BlDesc:Boolean;//升序、降序标记
//当接收到ColumnClick事件时调用过程MyColumnClick进行处理
procedure MyColumnClick(Sender: TObject; Column: TListColumn);
//当接收到Compare事件时调用过程MyCompare进行处理
procedure MyCompare(Sender: TObject; Item1,
Item2: TListItem; Data: Integer; var Compare: Integer);
protected public published end;procedure Register;implementationprocedure TSortListView.MyColumnClick(Sender: TObject; Column: TListColumn);
begin
IntSortCol := Column.Index;
Self.AlphaSort;
BlDesc := Not BlDesc;
end;procedure TSortListView.MyCompare(Sender: TObject; Item1,
Item2: TListItem; Data: Integer; var Compare: Integer);
beginIf IntSortCol = 0 then
Compare := CompareStr (Item1.Caption, Item2.Caption)
Else
Compare := CompareStr (Item1.SubItems [IntSortCol - 1],
Item2.SubItems [IntSortCol - 1]); If(BlDesc) Then
Compare := 0-Compare;
end;
procedure Register;
begin
RegisterComponents('Win32', [TSortListView]);
end;end.
解决方案 »
- 怎么在Cxgrid单元格内调字典里的数据?
- 向串口发送不同种类的命令(带有返回值),大虾们给些建议如何?
- 怎么在程序中动态改变打印机设置,别告诉我用printdialog。
- form2关闭后form1上的dbgrid怎么才能显出新的加入数据?
- 请问padarox的数据表必须有索引么,如果建立的时候没有索引,系统是否自动将第一个字段作为索引
- 使用动态数组和setlength分配空间,在98下是否会有不断消耗内存的问题?
- (很简单的一个错误,困扰到我到现在)高手请进!
- 请问一个有关MRPII的问题?
- 传统还是现代---面向对象与传统关系数据库
- 关于这个问题的解决是不是有更好的办法
- 怪事,用了Skin之后,有错了
- 数据库名中带有‘-’查询语句怎么写?进者有分
这个应该以前有很多相关的讨论,包括排序后在相应列上画一个箭头什么的。而且也有现成的做好的列表,楼主可搜一下