Solved

Bold and Color a field in cxGrid based on another field

Posted on 2008-10-23
7
6,473 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 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi TcxGrid group footer summary 3 323
Newbie Thread Programming 1 161
Delphi Dbf export problem to a Visual Foxpro application 6 208
Printing problem 2 102
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

821 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