Ver Mensaje Individual
  #3  
Antiguo 18-07-2022
Avatar de duilioisola
[duilioisola] duilioisola is offline
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.735
Reputación: 20
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
Veo que utilizas dos métodos de DBGrid que no deben utilizarse juntos...

De la ayuda de Delphi 6:
Note: If the Columns property has a State property of csDefault, the OnDrawDataCell event occurs before the OnDrawColumnCell. The OnDrawDataCell event is obsolete, and only included for backward compatibility. Do not set both an OnDrawDataCell event handler and an OnDrawColumnCell event handler.

Por otro lado, llamas a DefaultDrawColumnCell solo si se cumple la última condición.
Creo que esto deberías dejarlo fuera de la condición.

Código Delphi [-]
procedure TFrmPrincipal.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
Var
  Grid         : TStringGrid; // Esto debería ser TDBGrid(Sender)
  Texto        : String;
  Rectangulo   : TRect; // Esto no se necesita. Es lo mismo que el parametro Rect
begin
  //************** Auto Ancho *********************//
  if length(Column.Field.AsString) > Column.Field.Tag then
  begin
    Column.Field.Tag := length(Column.Field.AsString);
    Column.Field.DisplayWidth := Column.Field.Tag + 1;
  end;

  if (gdSelected in State) then
  begin
    // Color Celda Seleccionada
    DBGrid1.Canvas.Font.Color := clWhite;
    DBGrid1.Canvas.Brush.Color := clNavy;
    DBGrid1.Canvas.FillRect(Rect);
    DBGrid1.Canvas.TextOut(Rect.Left, Rect.Top,Column.Field.AsString);
  end
  else
  begin
    // Color resto de celdas
    if Column.FieldName = ComboBox2.Text then
      (Sender as TDBGrid).Canvas.Font.Color := clRed;

    (Sender as TDBGrid).Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Column.Field.AsString);

    // Codigo de DBGrid1DrawDataCell
    Rectangulo := Rect; // Esto no se necesita. Es lo mismo que el parametro Rect

    Grid := TStringGrid(Sender); // Esto debería ser TDBGrid(Sender)

    if Column.Field.IsBlob then
    begin
      Grid.Canvas.FillRect(Rect);
      Texto := Column.Field.AsString;
      DrawText(Grid.Canvas.Handle,
               PChar(Texto),
               StrLen(PChar(Texto)),
               Rectangulo, // Esto no se necesita. Es lo mismo que el parametro Rect
               DT_WORDBREAK);
    end;
    //***************************************************************************//

    if FrmData.ADOQuery1.FieldByName(ComboBox3.Text).AsString = Edit1.Text then
    begin
      DBGrid1.Canvas.Font.Color := clNavy;
      // DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;
  end;

  // Siempre debe ejecutarse
  DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

Última edición por duilioisola fecha: 18-07-2022 a las 10:43:17.
Responder Con Cita