Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7562933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:32:08+00:00 2026-05-30T13:32:08+00:00

When you have a TDBGrid, full row selection, and always show selection, even when

  • 0

When you have a TDBGrid, full row selection, and always show selection, even when not focused, and you want to fully owner-draw it, you have a choice of a deprecated event OnDrawDataCell , and a new event DrawColumnCell, I chose the latter and try this:

procedure TDbGridTestForm.mygridDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if  gdSelected in State then begin
      //      mygrid.DrawCellHighlight(Rect, State, Col, Row);
  mygrid.Canvas.Brush.Color := clHighlight;
  mygrid.Canvas.Font.Color := clHighlightText;
  mygrid.Canvas.FillRect(Rect);
  end;


  mygrid.DefaultDrawColumnCell(Rect, DataCol, Column, State);

end;

And what is driving me crazy is that focus indication (the highlight color and focus rectangle) are not drawn by the DefaultDrawColumnCell code, and I’m sure I should be invoking DrawCellHighlight instead of doing the FillRect hack I’m doing above.

If I turn on DefaultDrawing, I get one set of glitches (odd font painting issues) and if I turn it off, I get another set of glitches (no highlight even when gdSelected).

The code in DBGrids.pas DefaultDrawColumnCell does nothing other than paint the text. So clearly, you’re supposed to do more, if you take over all the drawing code yourself. However, the highlight drawing code built into Grids.pas, upon which DBGrids.pas depends, is not designed to be invoked from this context. I can’t figure out if I should be invoking DrawCellHighlight directly (shown commented out above), and figuring out Col and Row values, or if I should be writing my own complex version of TCustomGrid.DrawCellHighlight that handles all the various cases manually.

Surely this is so simple, and obvious, and I’m just overlooking it. NOte that I must leave DefaultDrawing off, and so I must completely paint from within my owner draw event, and that I must be able to run when theme services are not available, and I must use theme services when they are available. So I need to invoke TCustomGrid.DrawCellHighlight directly (and I don’t know how to), or I need to reimplement it entirely.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:32:09+00:00Added an answer on May 30, 2026 at 1:32 pm

    You’re better off invoking DrawCellHighlight due to the theme support that you’d need to implement yourself. Even though the row number is not provided to OnDrawColumnCell it doesn’t look like it’s even used by the DefaultDrawColumnCell code so you don’t have to try to calculate it internally:

    type
      tHackGrid = class(tDBGrid);
    
    procedure TTDbGridTestForm.myGridDrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      if gdSelected in State then begin
        tHackGrid(mygrid).DrawCellHighlight(Rect, State, Column.Index, 0);
      end;
      mygrid.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TDbGrid, and I can easily tell how many columns are in
I have a TDBGrid and have a Client dataset associated through a TDataSource. When
Have finally got a responsive site working (of a fashion). What I want to
I have a small button I want to add to the top left corner
Have you ever been frustrated by Visual Studio not re-evaluating certain watch expressions when
Have you written custom balancers for sharding to balance chunks not using the balancer
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have just started using Visual Studio Professional's built-in unit testing features, which as I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.