Solved

delphi

Posted on 2013-06-10
5
343 Views
Last Modified: 2013-06-26
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
Comment
Question by:AbhiJeet
  • 3
5 Comments
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 39234789
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
 

Author Comment

by:AbhiJeet
ID: 39235463
all rows from 3rd row are getting bold by this method.
0
 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 39236241
can you paste your code here? at least simplified. Did you set DefaultDrawing to false?
0
 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 39236998
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
 
LVL 6

Expert Comment

by:House_of_Dexter
ID: 39248849
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question