Para cambiar el color de las filas o celdas en un StringGrid en Delphi, puedes utilizar el evento OnDrawCell. Aquí tienes un ejemplo básico de cómo hacerlo:
Configura el evento OnDrawCell:
Selecciona tu StringGrid en el formulario.
Ve a la pestaña de eventos en el Inspector de Objetos.
Haz doble clic en el evento OnDrawCell para generar el manejador del evento.
Implementa el código en el manejador del evento:
Código:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
if ARow = 1 then // Cambia el color de la fila 1
begin
StringGrid1.Canvas.Brush.Color := clYellow; // Color de fondo
StringGrid1.Canvas.FillRect(Rect);
StringGrid1.Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, StringGrid1.Cells[ACol, ARow]);
end;
end;
para alinear los datos a la derecha tambien en ese evento DrawCell seria asi:
Código:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
var
CellText: string;
TextWidth: Integer;
begin
CellText := StringGrid1.Cells[ACol, ARow];
TextWidth := StringGrid1.Canvas.TextWidth(CellText);
StringGrid1.Canvas.TextRect(Rect, Rect.Right - TextWidth - 2, Rect.Top + 2, CellText);
end;