我從Wwdbgrid繼承過來,自己寫了一個排序功能,但是我點擊Title時那個三角圖標只顯示一下就不見了,問問大家是InforPower的問題還是我寫的不對.
unit DBGridXP;
interface
uses
SysUtils, Classes, Controls, Grids, DB, ADODB, Wwdbigrd, Wwdbgrid, DBGrids,
Graphics, Types;
type
TDBGridXP = class(TwwDBGrid)
private
protected
procedure DoTitleButtonClick(AFieldName: string); override;//排序
public
Bmp: TBitmap;
imgUpDown: TImageList;
constructor Create(AOwner: TComponent); override;
published
end;
implementation
{ TDBGridXP }
{$R other.RES}
constructor TDBGridXP.Create(AOwner: TComponent);
begin
inherited;
Bmp := TBitmap.Create;
Bmp.LoadFromResourceName(HInstance, 'UP');
imgUpDown := TImageList.CreateSize(Bmp.Width, Bmp.Height);
imgUpDown.AddMasked(Bmp, clFuchsia);
Bmp.LoadFromResourceName(HInstance, 'DOWN');
imgUpDown.AddMasked(Bmp, clFuchsia);
end;
procedure TDBGridXP.DoTitleButtonClick(AFieldName: string);
var
ColumnFieldName: string;
begin
inherited;
With DataSource.DataSet.FindField(AFieldName) do
begin
if not (FieldKind in [fkData,fkLookup]) then exit;
if FieldKind =fkData then
ColumnFieldName := UpperCase(AFieldName)
else
ColumnFieldName := UpperCase(KeyFields);
end;
with TADODataSet(DataSource.DataSet) do
begin
DisableControls;
if (Pos(ColumnFieldName,Sort) > 0) then
begin
if (Pos('ASC',Sort) > 0) then
Sort := ColumnFieldName +' DESC'
else
Sort := ColumnFieldName +' ASC'
end
else
Sort := ColumnFieldName +' ASC';
EnableControls;
end;
if Pos('ASC',TADODataSet(DataSource.DataSet).Sort) <> 0 then
imgUpDown.Draw(Canvas, DrawCellInfo.Rect.Right - 16, 1, 0)
else
imgUpDown.Draw(Canvas, DrawCellInfo.Rect.Right - 16, 1, 1);
end;
end.