简体   繁体   中英

How to conditionally format ReportBuilder field in Detail band depending on the other fields in then Detail band?

My DBText5 contains 0 or 1 and I would like to format DBText3 depending on DBText5 - I am using code ( How set font properties in calculated field using Digital-Metaphors Report Builder RAP ):

if (DBText5.FieldValue=1) then begin
  DBText3.Font.Bold := True;
end;

Both, DBText3 and DBText5 reside in Detail band. I have tried to put this code in the following events (of course I checked that only one event is active at each given time):

DBText3.OnPrint
DetailBand.OnBeforePrint
CustomVariableOnDetailsBand.Calculate

But in each case the DBText3 appears bold in all rows of the report. My intention is to make DBText3 bold in only those rows whose hase DBText5=1. Which event should I use or what other adaptations should I make?

Digital Metaphors own solution is to use Band.OnBeforePrint https://www.digital-metaphors.com/forums/discussion/9962/conditional-format but Detail.OnBeforePrint is not working form, as I said.

I created a quick text project and confirmed that this works.

I'm using Report Builder 19, Build 76, and Delphi 10.2.

procedure TForm1.ppDetailBand1BeforePrint(Sender: TObject);
begin
  if DBText5.fieldvalue = 20  then
    DbText5.Font.Style := [fsBold]
  else
    DbText5.Font.Style := [];
end;

You need to set the style for both the true and false condition.

Since you're using RAP, you can use

if DbText5.Fieldvalue = 1 then
  DbText5.Font.Bold := true
else
  DbText5.Font.Bold := false; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM