Lo primero es derivar el componente DBGrid. No puedes hacerlo (o al menos así a primeras no se ocurre como) desde el form.
Una vez derivado defines los dos métodos de dibujo en la parte privada.
Código Delphi
[-]
procedure __PaintArrowUp(Canvas: TCanvas; var Rect: TRect);
procedure __PaintArrowDown(Canvas: TCanvas; var Rect: TRect);
y su implementación:
Código Delphi
[-]
procedure TNeftaliDBGrid.__PaintArrowDown(Canvas: TCanvas; var Rect: TRect);
var
APolyLine: Array[0..2] of TPoint;
SaveCol, BrushCol : TColor;
begin
with Canvas do begin
SaveCol := Pen.Color;
BrushCol := Brush.Color;
Brush.Style := bsSolid;
Pen.Color := Self.FixedColor;
Brush.Color := Self.FixedColor;
Rectangle(Rect.Right-13, Rect.Top+3, Rect.Right-1, Rect.Top+15);
Pen.Color := clGray;
APolyLine[0]:=Point(Rect.Right-4, Rect.Top+5);
APolyLine[1]:=Point(Rect.Right-11, Rect.Top+5);
APolyLine[2]:=Point(Rect.Right-8, Rect.Top+11);
PolyLine(APolyLine);
Pen.Color := clWhite;
MoveTo(Rect.Right-7, Rect.Top+11);
LineTo(Rect.Right-4, Rect.Top+5);
Brush.Color := BrushCol;
Pen.Color := SaveCol;
end;
end;
procedure TNeftaliDBGrid.__PaintArrowUp(Canvas: TCanvas; var Rect: TRect);
var
SaveCol, BrushCol : TColor;
begin
with Canvas do begin
SaveCol := Pen.Color;
BrushCol := Brush.Color;
Brush.Style := bsSolid;
Pen.Color := Self.FixedColor;
Brush.Color := Self.FixedColor;
Rectangle(Rect.Right-13, Rect.Top+3, Rect.Right-1, Rect.Top+15);
Pen.Color := clGray;
MoveTo(Rect.Right-11, Rect.Top+11);
LineTo(Rect.Right-8, Rect.Top+5);
LineTo(Rect.Right-7, Rect.Top+5);
Pen.Color:=clWhite;
MoveTo(Rect.Right-7, Rect.Top+5);
LineTo(Rect.Right-4, Rect.Top+11);
LineTo(Rect.Right-11, Rect.Top+11);
Brush.Color := BrushCol;
Pen.Color := SaveCol;
end;
end;
Para poder pintar la flecha cuando te interese debes redefinir el método para dibujar una celda:
Código Delphi
[-]
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
Y en la implementacion hacer las comprobaciones de fila y columna, para que sólo te lo pinte en la fila de títulos y en la columna que quieres. En éste ejemplo las columnas estñán como constantes, pero seguramente tú deberaás obtenerlas de alguna variable/propiedad (por ejemplo la que el usuario pulse con el ratón)
Código Delphi
[-]
procedure TNeftaliDBGrid.DrawCell(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState);
begin
inherited;
if (ARow <> 0) then begin
Exit;
end;
if (ACol = 3) then begin
__PaintArrowUp(Canvas, ARect);
end;
if (ACol = 4) then begin
__PaintArrowDown(Canvas, ARect);
end;
end;
Si tienes algun problema con el código ya me dirás...
NOTA: He subido todo el texto completo con alguna imagen y el código en un ZIP a la dirección:
http://neftali.clubdelphi.com/delphi...cha_ordenacion