Jump to content
Henry Olive

Make Bold DBRrid Row Color

Recommended Posts

Good Day

 

My DBGrid has JUST 2 rows (cant be more)

Group   Jan  Feb.....

-------------------

A           10    20

B            12   16

 

How can i make JUST second row's Fonts to Bold like below ?

Group   Jan  Feb.....

-------------------

A           10    20

         12   16

 

Thank You

 

Share this post


Link to post

Look at this help entry for an overview of how to modify the way a TDBGrid is drawn. In your case set the DefaultDrawing property of the grid to false and attach a handler to the OnDrawColumnCell event. The handler can check the attached dataset's current row to see what row it has to draw. If it is the first just call the grid's DefaultDrawColumnCell method directly. If it is the second row change the grid.canvas.font to bold first and then call DefaultDrawColumnCell. That should do what you want.

Share this post


Link to post

Thank you Peter

My code :

 

procedure TManTargets.DBGrid2DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if CDS2.Eof then
  begin
     DBGrid2.Font.Style:=[fsBold]; 
     DbGrid2.Canvas.FillRect(rect);
     DBGrid2.DefaultDrawColumnCell(Rect, DataCol, Column, State);
  end;

end;

 

I dont get error msg. but the code doesnt make Bold the last row of the dbgrid

 

Share this post


Link to post

At the second row is not the end of the dataset, eof is going to be true when you call next on the last row. You can check recno or a value of the group field.

Share this post


Link to post

Here

procedure TForm3.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
begin
  //detect last row of DataSet
  if DBGrid1.DataSource.DataSet.RecNo = DBGrid1.DataSource.DataSet.RecordCount then
    DBGrid1.Canvas.Font.Style := [fsBold];

  //draw cell
  DBGrid1.DefaultDrawDataCell(Rect, Field, State);
end;

Don't forget to set property DefaultDrawing into False to prevent draw data few times

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×