Ver Mensaje Individual
  #1  
Antiguo 21-08-2015
wilcg wilcg is offline
Miembro
 
Registrado: abr 2014
Posts: 107
Reputación: 11
wilcg Va por buen camino
Flotantes en campo DBGridEh mediante evento

Amigos del foro tengo este codigo en el evento OnDrawColumnCell de un DBGridEh por corregir algunos puntos.
Código Delphi [-]
procedure DBGridEhDrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumnEh; State: TGridDrawState);
const
  // Windwos classic
  CtrlState: Array[Boolean] of Integer = (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or
  DFCS_CHECKED);
  // Windows xp
  CtrlStateXP: Array [Boolean] of TThemedButton = (tbCheckBoxUncheckedNormal,
  tbCheckBoxCheckedNormal);
var
  R      : TRect;
  uFormat: LongWord;
  Details: TThemedElementDetails;
begin
  uFormat := DT_SINGLELINE or DT_VCENTER or DT_END_ELLIPSIS;
  case Column.Alignment of
    taLeftJustify : uFormat := uFormat or DT_LEFT;
    taRightJustify: uFormat := uFormat or DT_RIGHT;
    taCenter      : uFormat := uFormat or DT_CENTER;
  end;

  with TDBGridEh(Sender) do
  begin
    if Datasource.DataSet.RecNo mod 2 = 0 then
      Canvas.Brush.Color := $00F5F5F5
    else
      Canvas.Brush.Color := clWhite;
    Canvas.Font.Color := $00606060;

    if gdSelected in State then
   begin
     Canvas.Brush.Color := $00A6E8FF;
     Canvas.Font.Color := clHotLight;
     Canvas.Font.Name := 'Tahoma';
     Canvas.Font.Size := 9;
   end ;
    DefaultDrawColumnCell(rect,DataCol,Column,State);
    R := Rect;
   Canvas.FillRect(R);
   DrawText(Canvas.Handle, @Column.Field.AsString[1], -1, R, uFormat);
   // Campo Booleano
   if Column.Field.DataType = ftBoolean then
   begin
     Canvas.FillRect(Rect);
     if ThemeServices.ThemesEnabled then
     begin
       Details := ThemeServices.GetElementDetails(CtrlStateXP[Column.Field.AsBoolean]);
       ThemeServices.DrawElement(Canvas.Handle, Details, Rect);
     end else
     begin
       R.Left   := Rect.Left + 2;
       R.Right  := Rect.Right - 2;
       R.Top    := Rect.Top + 2;
       R.Bottom := Rect.Bottom - 2;
       DrawFrameControl(Canvas.Handle, R, DFC_BUTTON, CtrlState[Column.Field.AsBoolean]);
     end;
   end;
  end;
end;
Lo que hace es:
Primero ajusta el texto del campo a su longitud y muestra 3 puntitos
Segundo Dibuja un checkbox en cada campo booleano.

luego viene lo que quiero, es que formatee un campo numerico ejemplo S/. 123.00 lo he estado
haciendo en la propiedad del DisplayFormat del campo, aparentemente funciona sin el codigo. Luego con
el codigo en el evento OnDrawColumnCell del DBGridEh no funciona.
espero que me hayan entendido y me puedan ayudar.
Responder Con Cita