Solved

Change text of field in twwdbgrid when selected (highlighted)

Posted on 2008-10-06
4
1,260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 15

Assisted Solution

by:mikelittlewood
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
   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
ID: 22658389
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
ID: 22663489
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: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);
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month4 days, 23 hours left to enroll

635 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