Solved

Bold and Color a field in cxGrid based on another field

Posted on 2008-10-23
7
6,332 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
7 Comments
 
LVL 36

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 36

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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 36

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

23 Experts available now in Live!

Get 1:1 Help Now