?
Solved

Bold and Color a field in cxGrid based on another field

Posted on 2008-10-23
7
Medium Priority
?
6,644 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 38

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 38

Accepted Solution

by:
Geert Gruwez earned 480 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 38

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

Technology Partners: 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!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month10 days, 13 hours left to enroll

770 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