Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   colorear filas de un dbgrid (https://www.clubdelphi.com/foros/showthread.php?t=7045)

soyhugo 31-01-2004 19:35:35

colorear filas de un dbgrid
 
¿alguien sabe el código para colorear las líneas de un dbgrid alternativas en dos colores distintos? gracias.

Gydba 31-01-2004 20:47:42

Fijate si este código te ayuda (Tenés que usar el evento DrawDataCell del componente):
Código:

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState);
var
  iRowNumber : Integer;
begin
  with (Sender as TDBGrid), Canvas do begin
      iRowNumber := (Rect.Top + Rect.Bottom) div ((1+Rect.Bottom - Rect.Top)*2);
        if Odd(iRowNumber) then Brush.Color := clYellow
        else Brush.Color := clWhite;
      FillRect(Rect);
      DefaultDrawDataCell(Rect, Field, State);
  end;
end;

Como dato interesante el componente rxDBGrid de las rxlib tiene propiedades un tanto mas avanzadas que el DBGrid.

rmora 05-08-2010 22:21:03

Pintar celdas alternas con texto
 
Cita:

Empezado por Gydba (Mensaje 28280)
Fijate si este código te ayuda (Tenés que usar el evento DrawDataCell del componente):
Código:

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState);
var
  iRowNumber : Integer;
begin
  with (Sender as TDBGrid), Canvas do begin
      iRowNumber := (Rect.Top + Rect.Bottom) div ((1+Rect.Bottom - Rect.Top)*2);
        if Odd(iRowNumber) then Brush.Color := clYellow
        else Brush.Color := clWhite;
      FillRect(Rect);
      DefaultDrawDataCell(Rect, Field, State);
  end;
end;

Como dato interesante el componente rxDBGrid de las rxlib tiene propiedades un tanto mas avanzadas que el DBGrid.

Hola amigos, el ejemplo descrito a mi me funciono de maravilla, sin embargo cuando estas celdas tienen texto, el texto desaparece o no se puede visualizar. Por favor podrían decirme como puedo hacer???. Estoy utilizando el componente tRxDBLib.

Gracias de antemano

rgstuamigo 05-08-2010 22:39:26

Cita:

Empezado por rmora (Mensaje 372760)
...sin embargo cuando estas celdas tienen texto, el texto desaparece o no se puede visualizar. Por favor podrían decirme como puedo hacer???. Estoy utilizando el componente tRxDBLib.

En ese caso puedes cambiar el color del texto agregando una linea de código:
Código Delphi [-]
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState);
var
   iRowNumber : Integer;
begin
   with (Sender as TDBGrid), Canvas do begin
      iRowNumber := (Rect.Top + Rect.Bottom) div ((1+Rect.Bottom - Rect.Top)*2);
         if Odd(iRowNumber) then Brush.Color := clYellow
         else Brush.Color := clWhite;
       Font.Color:=clBlack;// <-Aqui le estoy poniendo que los textos sean negros
      FillRect(Rect);
      DefaultDrawDataCell(Rect, Field, State);
   end;
end;
Saludos...:)

rmora 06-08-2010 00:20:37

Gracias por tu respuesta, sin embargo ahora me encuentro con el siguiente problema:

Mi componente (rxDbLib) posee estos parametros:

GridDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);

Por lo tanto el código se cae ya que no recibe el parámetro "Field" como lo indica el código anterior.
Tener idea que puedo cambiar para lograr lo que deseo??

De antemano gracias por tu ayuda.


La franja horaria es GMT +2. Ahora son las 13:08:57.

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