Solved

Change text of field in twwdbgrid when selected (highlighted)

Posted on 2008-10-06
4
1,245 Views
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
        begin
          (Sender as TwwDBGrid).Canvas.Font.color := clBlue;
          (Sender as TwwDBGrid).Canvas.TextRect(rect,rect.left,rect.Top + 2, qry.FieldByName('Subject').asString);
        end;

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?
0
Comment
Question by:weimha
4 Comments
 
LVL 15

Assisted Solution

by:mikelittlewood
mikelittlewood earned 250 total points
Comment Utility
I don't use the WollToWoll components, but based on the standard DBGrid component it might be something like
   if s = 'SomeCondition' then

   begin

      if (Sender as TwwDBGrid).selectedField = field then

         (Sender as TwwDBGrid).Canvas.Font.color := clAqua

      else

         (Sender as TwwDBGrid).Canvas.Font.color := clBlue;
 

      (Sender as TwwDBGrid).Canvas.TextRect(rect,rect.left,rect.Top + 2, qry.FieldByName('Subject')

   end;

Open in new window

0
 
LVL 1

Assisted Solution

by:swiatlo
swiatlo earned 250 total points
Comment Utility
TwwCustomDBGrid.OnCalcCellColors

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
0
 

Accepted Solution

by:
weimha earned 0 total points
Comment Utility
I was able to use the "STATE" variable to get what I needed.  Thanks.
 if (gdSelected in State) then
0
 
LVL 4

Expert Comment

by:SurferJoe
Comment Utility
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);

begin
 

  with (Sender as TwwDBGrid), ClientDataSetCosts do begin

    if (Field.Value < 0) then

      Canvas.Brush.Color := 8421631

    else

      Canvas.Brush.Color := 8454016;
 

    Canvas.TextRect( rect, rect.left, rect.Top + 2, FieldByName( Field.FieldName).AsString);
 

  end;

end;

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now