Ver Mensaje Individual
  #4  
Antiguo 21-06-2014
viveba viveba is offline
Miembro
 
Registrado: nov 2006
Posts: 24
Reputación: 0
viveba Va por buen camino
Supongo ya solucionaste tu problema, para otros foristas interesados, lo siguiente puede ser una solución:

Código Delphi [-]
procedure TForm2.FormCreate(Sender: TObject);
begin
  Grilla.ColCount   := 10;
  Grilla.Cells[0,0] := 'Titulo 1';
  Grilla.Cells[1,0] := 'Titulo 2';
  Grilla.Cells[2,0] := 'Titulo 2';
  Grilla.Cells[3,0] := 'Titulo 4';
  Grilla.Cells[4,0] := 'Titulo 5';
  Grilla.Cells[5,0] := 'Titulo 6';
  Grilla.Cells[6,0] := 'Titulo 7';
  Grilla.Cells[7,0] := 'Titulo 8';
  Grilla.Cells[8,0] := 'Titulo 9';
  Grilla.Cells[9,0] := 'Titulo 10';

  Grilla.ColWidths[0] := 65;
  Grilla.ColWidths[1] := 70;
  Grilla.ColWidths[2] := 70;
  Grilla.ColWidths[3] := Grilla.ColWidths[2];
  Grilla.ColWidths[4] := Grilla.ColWidths[2];
  Grilla.ColWidths[5] := 75;
  Grilla.ColWidths[6] := Grilla.ColWidths[5];
  Grilla.ColWidths[7] := 85;
  Grilla.ColWidths[8] := 70;
end;

procedure TForm2.FormResize(Sender: TObject);
var
  i: byte;
  c: word;

begin
  c := 0;
  for i := 0 to Grilla.ColCount - 2 do
    c := c + Grilla.ColWidths[i];
  Grilla.ColWidths[Grilla.ColCount - 1] := Grilla.Width - c - 35; //35 según sea el ancho del scrollbar de la grilla, su relación al formulario, etc.
end;

//El siguiente código se basa en lo disponible en el material "delphi al límite" (http://delphiallimite.blogspot.com/)

procedure TForm2.GrillaDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
var
  Alineacion : TAlignment;  // Alineación que le vamos a dar al texto
  F          : Cardinal;    // Permite dibujar el texto con DT_END_ELLIPSIS

begin
  with Grilla.Canvas do
  begin // Lo primero es tomar la fuente por defecto que le hemos asignado al componente
    Font.Name := Grilla.Font.Name;
    Font.Size := Grilla.Font.Size;

    if ARow = 0 then begin //todos los títulos al centro
      Font.Style := [fsBold];     // y negrita
      Alineacion := taCenter
    end else
      if ACol = 0 // Si es la columna del 'titulo 1' alineamos a la derecha
        then Alineacion := taRightJustify
        else Alineacion := taCenter;

    if gdFixed in State then begin // ¿Es una celda fija de sólo lectura?
      Brush.Color := clNavy;     // le ponemos azul de fondo
      Font.Color := clWhite      // fuente blanca
    end else begin
      if gdFocused in State then begin // ¿Esta enfocada la celda?
        if (pos('clave por si se quiere otro color el la celda enfocada', LowerCase(Grilla.Cells[3,aRow])) > 0) then
          Brush.Color := clFuchsia  // fondo violeta
        else if (pos('otra palabra clave', LowerCase(Grilla.Cells[2,aRow])) > 0) then
            Brush.Color := clGreen // fondo verde
          else Brush.Color := clRed;  // fondo rojo
        Font.Color  := clWhite;    // fuente blanca
        Font.Style  := [fsBold]    // y negrita
      end else begin // Para el resto de celdas el fondo lo ponemos blanco
        Brush.Color := clWindow;
        Font.Color  := clBlack;
        Font.Style  := []
      end
    end;
    FillRect(Rect);

    //Personalización, para el caso de modificar el ancho de las columnas, el texto no se salga
    F := DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX or DT_END_ELLIPSIS;
    if Grilla.Cells[aCol,aRow] <> '' then begin
      case Alineacion of
        taLeftJustify : F := F or DT_LEFT;
        taCenter      : F := F or DT_CENTER;
        taRightJustify: F := F or DT_RIGHT
      end;
      setbkmode(Handle, 0);
      DrawText (Handle, Grilla.Cells[ACol,ARow], -1, Rect, F)
    end
  end
end;

esto lo probé en delphi XE4
Responder Con Cita