Change text of field in twwdbgrid when selected (highlighted)

Posted on 2008-10-06
Last Modified: 2012-08-13
Currently in OnDrawDataCell function of a TwwDBGrid, I change the color of the text in a particular field if certain criteria is meet.  For instance:

 if s = 'SomeCondition' then
          (Sender as TwwDBGrid).Canvas.Font.color := clBlue;
          (Sender as TwwDBGrid).Canvas.TextRect(rect,rect.left,rect.Top + 2, qry.FieldByName('Subject').asString);

I am changing the field in some rows to have blue text.  Not all rows have this text color.  However, when a row with the blue text is selected (highlighted) the text is hard to see.  This is becuase the row is "highligted" in a shade of blue too.  I would like the text to be aqua if the row is highlighted and blue if it is not.  Does anyone know how to do this?
Question by:weimha
LVL 15

Assisted Solution

mikelittlewood earned 250 total points
ID: 22651236
I don't use the WollToWoll components, but based on the standard DBGrid component it might be something like
   if s = 'SomeCondition' then
      if (Sender as TwwDBGrid).selectedField = field then
         (Sender as TwwDBGrid).Canvas.Font.color := clAqua
         (Sender as TwwDBGrid).Canvas.Font.color := clBlue;
      (Sender as TwwDBGrid).Canvas.TextRect(rect,rect.left,rect.Top + 2, qry.FieldByName('Subject')

Open in new window


Assisted Solution

swiatlo earned 250 total points
ID: 22658389

TCalcCellColorsEvent = procedure(Sender: TObject; Field: TField; State: TGridDrawState; Highlight: Boolean; AFont: TFont; ABrush: TBrush) of object;

you have a Highlight: Boolean input param
use OnCalcCellColors instead of OnDrawDataCell

Accepted Solution

weimha earned 0 total points
ID: 22663489
I was able to use the "STATE" variable to get what I needed.  Thanks.
 if (gdSelected in State) then

Expert Comment

by:Greg Rowland
ID: 24467857
This all works great. Only in my case the values are currency. The currency formatting  gets striped in the process.

What's up with that?
procedure TCostsf.wwDBGrid1DrawDataCell(Sender: TObject;
  const Rect: TRect; Field: TField; State: TGridDrawState);
  with (Sender as TwwDBGrid), ClientDataSetCosts do begin
    if (Field.Value < 0) then
      Canvas.Brush.Color := 8421631
      Canvas.Brush.Color := 8454016;
    Canvas.TextRect( rect, rect.left, rect.Top + 2, FieldByName( Field.FieldName).AsString);

Open in new window


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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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