试试下面的方法:
var iCol : Integer;
procedure TForm1.FormCreate(Sender: TObject);
begin
iCol := 100;//初始化, 这个值应大于字段数
end;
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
begin
iCol := Column.Index ;
DBGrid1.Refresh ;
end;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Column.Index = iCol then setbkcolor(dbgrid1.canvas.handle,clBlue)
else setbkcolor(dbgrid1.canvas.handle,clwhite);
dbgrid1.Canvas.TextRect(rect,0,0,Column.Field.AsString);
dbgrid1.Canvas.Textout(rect.Left,rect.Top,Column.field.AsString);
end;