#1 2013-02-04 16:26:11

coblongpamor
Member
From: Bali-Indonesia
Registered: 2010-11-07
Posts: 130
Website

How to use OnDrawCellBackground of TSQLTableToGrid?

i want to set the font as Bold in the TSQLTableToGrid row for some special condition.
this code is working with font as Bold, but i can not select the row.

procedure TBPBaseMainForm.DoOnDrawCellEvent(Sender: TObject; ACol, ARow: Longint; Rect: TRect; State: TGridDrawState);
var T2G: TSQLTableToGrid;
    ATIndex: Integer;
    ATValue: Integer;
begin
  T2G:= TSQLTableToGrid.From(TDrawGrid(Sender));
  if not(gdFocused in State) then begin
    ATIndex:= T2G.Table.FieldIndex('AccountType');
      ATValue:= T2G.Table.GetAsInteger(ARow,ATIndex);
      with TDrawGrid(Sender) do begin
        if ATValue = 3 then
          Canvas.Font.Style:= Canvas.Font.Style + [fsBold]
        else
          Canvas.Font.Style:= Canvas.Font.Style - [fsBold];
      end;
  end;
end;

what is missing?

Offline

#2 2013-02-05 07:58:18

coblongpamor
Member
From: Bali-Indonesia
Registered: 2010-11-07
Posts: 130
Website

Re: How to use OnDrawCellBackground of TSQLTableToGrid?

Solved.
I just set the DefaultDrawing to True after Setting Canvas.Font.Style

procedure TBPBaseMainForm.DoOnDrawCellEvent(Sender: TObject; ACol, ARow: Longint; Rect: TRect; State: TGridDrawState);
var T2G: TSQLTableToGrid;
    ATIndex: Integer;
    ATValue: Integer;
begin
  T2G:= TSQLTableToGrid.From(TDrawGrid(Sender));
  ATIndex:= T2G.Table.FieldIndex('AccountType');
  ATValue:= T2G.Table.GetAsInteger(ARow,ATIndex);
//  if not(gdFixed in State) then
  with TDrawGrid(Sender).Canvas do begin
    if ATValue = 3 then
      Font.Style:= Font.Style + [fsBold]
    else
      Font.Style:= Font.Style - [fsBold];
      TDrawGrid(Sender).DefaultDrawing:= True; //Just add this line;
  end;
end;

But i loss the look and feel of the header.
any idea?

thanks

Offline

#3 2013-02-05 08:01:20

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,669
Website

Re: How to use OnDrawCellBackground of TSQLTableToGrid?

Checking ARow>0 ?

Offline

#4 2013-02-05 08:34:48

coblongpamor
Member
From: Bali-Indonesia
Registered: 2010-11-07
Posts: 130
Website

Re: How to use OnDrawCellBackground of TSQLTableToGrid?

not working with checking ARaw>0.

...
if ARow > 0 then
  with TDrawGrid(Sender).Canvas do begin
    if ATValue = 3 then
      Font.Style:= Font.Style + [fsBold]
    else
      Font.Style:= Font.Style - [fsBold];
//    if ARow > 0 then
      TDrawGrid(Sender).DefaultDrawing:= True;
  end;
...

Offline

Board footer

Powered by FluxBB