procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
i,ii:integer;
strFieldName:string;
cStr:string;
c:TColumn;
begin
for ii:=0 to TDBGrid(Column.Grid).Columns.Count-1 do
begin
c:=TDBGrid(Column.Grid).Columns[ii];
cStr:=c.Title.Caption;
if (pos('▲',cStr)=1) or (pos('▼',cStr)=1) then
begin
Delete(cStr,1,1);
c.Title.Caption:=cStr;
end;
end;
for i:= 1 to TDBGrid(Column.Grid).Columns.Count do
begin
//恢复所有标题字体为默认
DBGrid1.Columns[i-1].Title.Font.Color := clWindowText;
DBGrid1.Columns[i-1].Title.Font.Style := [];
end;
if ADOQuery1.Sort<>(Column.FieldName+' ASC') then //判断原排序方式
begin
ADOQuery1.Sort := Column.FieldName+' ASC';
//Column.Title.Font.Color := clRed; //改变标题行字体为红色,表示当前的排序方式为升序
Column.Title.Font.Style := [fsBold];
Column.Title.Caption:='▲'+Column.Title.Caption; //标题加上三角形表示当前排序方式为升序;
end
else
begin
ADOQuery1.Sort := Column.FieldName+' DESC';
//Column.Title.Font.Color := clBlue; //改变标题行字体为蓝色,表示当前的排序方式为降序
Column.Title.Font.Style := [fsBold];
Column.Title.Caption:='▼'+Column.Title.Caption; //标题加上倒三角形表示当前排序方式为降序;
end;
end;