Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 348
  • Last Modified:

delphi

in tdrawgrid i need to change the font  of one specific row, based on the value of one field.

When i am trying this with onDrawcell event, as below:

Sender.Canvas.Font.Style := [fsBold], font of whole grid is changing.

Any idea?
0
AbhiJeet
Asked:
AbhiJeet
  • 3
1 Solution
 
Sinisa VukCommented:
You should check if specific cell row/column is drawing:

...
   Sender.Canvas.Font.Style := [];
   if (ARow = 3) and ... then //check if it is valid row 
   begin
      Sender.Canvas.Font.Style := [fsBold];
   end;
...

Open in new window

0
 
AbhiJeetAuthor Commented:
all rows from 3rd row are getting bold by this method.
0
 
Sinisa VukCommented:
can you paste your code here? at least simplified. Did you set DefaultDrawing to false?
0
 
Sinisa VukCommented:
Made simple example:
procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  s: String;
begin
  TDrawGrid(Sender).Canvas.Brush.Color := TDrawGrid(Sender).Color;
  TDrawGrid(Sender).Canvas.Brush.Style := bsSolid;
  TDrawGrid(Sender).Canvas.FillRect(Rect);

  TDrawGrid(Sender).Canvas.Font.Style := [];
  if (ARow = 3) then //check if it is valid row
  begin
    TDrawGrid(Sender).Canvas.Font.Style := [fsBold];
  end;

  s := 'fdfdgfdgfd';
  TDrawGrid(Sender).Canvas.TextOut(
    Rect.Right - TDrawGrid(Sender).Canvas.TextWidth(s) - 2,
    Rect.Top + 8 - (TDrawGrid(Sender).Canvas.TextHeight(s) div 2),
    s
    );
end;

Open in new window

0
 
House_of_DexterCommented:
change this to

  if (ARow = 3) then //check if it is valid row
  begin
    TDrawGrid(Sender).Canvas.Font.Style := [fsBold]
  end else
    TDrawGrid(Sender).Canvas.Font.Style := [];

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now