Solved

Bold and Color a field in cxGrid based on another field

Posted on 2008-10-23
7
6,534 Views
Last Modified: 2013-11-23
I have a DevExpress TcxGrid attached to an Oracle Dataset through a Data Source. It displays the data fine, but I'd like to have the Name field/column have the cell data shown in Bold and possibly with a different text color, but only for each row where the row's Finished field is null.

Thus the grid should look a bit like this:
Name        Finished
---------    ---------------
Smith        04-01-2008
BROWN  
Jones       04-01-2008

.. but obviously with bold or blue text in Name instead of capitalising.

 Martin C
0
Comment
Question by:MartinC
[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
7 Comments
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 22793535
I don't have Delphi here,so the syntax may not be accurate, so here goes:

look at the views style events

there should be one OnGetContentStyle

first Add a Style repository
Edit it and add a style item for cxsFinished and cxsNotFinished
change the Text Color and/or other options of this Style item

in the OnGetContentStyle

procedure TForm1.viewOnGetContentStyle(Sender: TObject; ARecord: TcxGridRecord; out aStyle: TcxStyle);
begin
  if ARecord.Values[colFinished.Index] = 1then  // assuming 1 for true
    AStyle := cxsFinished
  else
    AStyle := cxsFinished;
end;

if you need to set the look of the style, change the styleitems

G
 
0
 

Author Comment

by:MartinC
ID: 22793812
Geert:

OK, I did all that and it works except for one thing: it makes ALL the columns bold. Is there a way of only allowing ONE (or maybe two) fields to be affected?
Martin C
0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 120 total points
ID: 22793819
yes, no problem, now that i have Delphi here:

procedure TForm1.viewPlanningStylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);

AItem = the column the grid/view is currently rendering

off course, you need to change it to your columns




procedure TForm1.viewPlanningStylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
  if (AItem = colName) or (AItem = colFirstName) then 
  begin
    if ARecord.Values[colFinished.Index] = 1 then  // assuming 1 for true
      AStyle := cxsFinished
    else
      AStyle := cxsFinished;
  end;   
end;

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:TheRealLoki
ID: 22801389
that looks wrong to me, I thought you wanted it bold when "finished" was null ?
All you need is a "default" and then handle the unfinished and change the style
Here's how I'd do it...
procedure TForm1.cxGrid1DBTableView1StylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
  AStyle := Style_Default; 
  if assigned(ARecord) then
  begin
    if ARecord.Values[cxGrid1DBTableView1FINISHED.Index] = null then  
      AStyle := style_Finished
  end;   
end;

Open in new window

0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 22806097
no need to provide a default with devexpress
there allready is one
0
 

Author Comment

by:MartinC
ID: 22809138
Loki: Yep, I had managed to work out the finished = null bit myself.

Geert: Thanx, didn't realise AItem could be the column. Points awarded.

0
 

Expert Comment

by:rmaxwell2192
ID: 26123584
This answer helped me a lot.  One thing I would add is that if you allow grouping of columns, the event will fire on non-data rows, and you may get exceptions if you assume every call to the event handler is working on a row of data.  It might be firing on a header row.

I added a check for:

if ARecord.IsData then begin
 ....do stuff
end

To make sure I do not have a problem when grouping.


0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…

739 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