Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Celda a la Derecha (https://www.clubdelphi.com/foros/showthread.php?t=96861)

pruz 27-09-2024 23:20:57

Celda a la Derecha
 
1 Archivos Adjunto(s)
Buenas tardes:

Estoy usando StringGrid, pero necesito mostrar los datos numerico a la DERECHA, y entre esta rutina

Código Delphi [-]
Procedure TFGrillaComprobante.GrillaComprobanteDrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);

 procedure WriteText(StringGrid: TStringGrid; ACanvas: TCanvas; const ARect: TRect;
    const Text: string; Format: Word);
  const
    DX = 2;
    DY = 2;
  var
    S: array[0..255] of Char;
    B, R: TRect;
  begin
    with Stringgrid, ACanvas, ARect do
    begin
      case Format of
        DT_LEFT: ExtTextOut(Handle, Left + DX, Top + DY,
            ETO_OPAQUE or ETO_CLIPPED, @ARect, StrPCopy(S, Text), Length(Text), nil);

        DT_RIGHT: ExtTextOut(Handle, Right - TextWidth(Text) - 3, Top + DY,
            ETO_OPAQUE or ETO_CLIPPED, @ARect, StrPCopy(S, Text),
            Length(Text), nil);

        DT_CENTER: ExtTextOut(Handle, Left + (Right - Left - TextWidth(Text)) div 2,
            Top + DY, ETO_OPAQUE or ETO_CLIPPED, @ARect,
            StrPCopy(S, Text), Length(Text), nil);
      end;
    end;

  end;

  procedure Display(StringGrid: TStringGrid; const S: string; Alignment: TAlignment);
  const
    Formats: array[TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER);
  begin
    WriteText(StringGrid, StringGrid.Canvas, Rect, S, Formats[Alignment]);
  end;

begin

  if (Arow > 0) and (ACol in [1,2,3,4,6,7,8,9,10]) then
     Display(GrillaComprobante, GrillaComprobante.Cells[ACol, ARow], taRightJustify) ;

  if (Arow mod 2) = 0 then begin
     GrillaComprobante.Canvas.Brush.Color := clBlue
  end else begin
     GrillaComprobante.Canvas.Brush.Color := clred

  end;

end;


La cual funciona perfectamente.
Pero con el GoRowSelect=True, cuando selecciono la fila, esta queda completamente en negro, no deja ver la informacion
(imagen comprobante.png)


Pero si dejo GoRowSelect=False, ahi me deja ver toda la informacion de la Fila


Pregunta, hay solucion o no, porque quiero dejar la GoRowSelect=True.

Gracias

navbuoy 29-09-2024 22:34:45

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;


pruz 01-10-2024 15:42:05

Gracias, lo probare y les cuento

Saludos

pruz 01-10-2024 17:10:50

Hola, ya probe y funcion perfecto.

solo le hice una mejora, para las cabeceras de columna, ponerlas de otro color.


Código Delphi [-]
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
  if ARow = 0 then   StringGrid1.Canvas.Brush.Color := clSilver // Color de fondo cabezera de columna
  else   StringGrid1.Canvas.Brush.Color := clYellow; // Color de fondo todas las demas columnas

    StringGrid1.Canvas.FillRect(Rect);
    StringGrid1.Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, StringGrid1.Cells[ACol, ARow]);

end;

Gracias

navbuoy 08-10-2024 11:58:06

fenomenal entonces


La franja horaria es GMT +2. Ahora son las 18:34:24.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi