Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Conexión con bases de datos
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Conexión con bases de datos

 
 
Herramientas Buscar en Tema Desplegado
  #3  
Antiguo 18-07-2022
Avatar de duilioisola
[duilioisola] duilioisola is offline
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.806
Poder: 22
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
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Problema al Pintar DBGrid MaMu Varios 5 11-06-2007 09:53:36
Pintar un dbGRid sebas78 Gráficos 5 22-07-2006 16:06:36
Pintar Fila del DBGrid Palmiro Conexión con bases de datos 2 05-04-2006 23:25:51
Pintar filas DbGrid lunatiko Varios 5 05-07-2005 15:11:51
pintar filas de un dbgrid febito Varios 1 01-04-2004 16:50:20


La franja horaria es GMT +2. Ahora son las 15:14:20.


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