Solved

Bold and Color a field in cxGrid based on another field

Posted on 2008-10-23
7
6,384 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 284
select query - oracle 16 91
Delphi inherited method 6 60
How to load 2 images in same column in Delphi 2 27
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 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

12 Experts available now in Live!

Get 1:1 Help Now