Highlighting Cells during run time

edited 5:33AM in FastReport 4.0
Hi,
I am evaluating FastReports VCL v4.11.8 for C++ Builder 2007. I have been relatively successfully so far but I cannot establish how to modify/highlight an individual cell based on values read at run time. If I am able to overcome this minor hurdle I plan to commit to purchasing FastReports.

In my report each column can have a different Highlight threshold (only known at run time) so setting it at design time is not an option. If a cell value exceeds this 'Alert' value then the cell needs to be highlighted red. The project primarily consists of TFrxCrossView object populated with data during frxReport1BeforePrint.

I can see from various threads that you often refer users to the user manual, so prior to posting this thread I investigated thoroughly any information on how to format cells during run time. e.g. Font colors and highlighting, Access report objects from a code. I have spent a lot of time browsing the forum also and have investigated the use of HTMLTags

Main question:
1) How can I Highlight/modify a cell based on a condition only known at run time (TFrxCrossView+frxReport1BeforePrint). Each column within the CrossView object can have a different Highlight condition. If highlight is not possible changing the font colour is an option.

Follow on:
2) Is it possible to assign a cell colour when adding the value i.e. crossView->AddValue()?
3) Is it possible to get the new Cell x,y 'coordinates' immediately after crossView->AddValue()?
4) Is the OnPrintCell event accessible outside the designer / FR scripts. If so can the colour be changed within this event?

I have attached the example test *.fr3 and a screenshot of the table to give you a better understanding of the layout etc.

[topic="http://www.fast-report.com/en/forum/index.php?showtopic=5901&hl=highlight"]Highlight[/topic]
[topic="http://www.fast-report.com/en/forum/index.php?showtopic=8047&hl=cell"]Cell[/topic]

Thanks in advance for your feedback. Feedback referencing C++ would be greatly appreciated.

D'Arcy

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 5:33AM
    darcy here is sample of delphi code in the report to modify the cell.
    make report 2 pass load values into array then set the color on the final pass.
    sorry i am not a c programmer but you should be able to conver.

    begin
    if engine.finalpass then
    begin
    //compare column value against array value and set highlight
    if (Value <> Null)then
    begin
    if (value = colmin[columnindex]) and not cross1.IsGrandTotalColumn(columnindex) then memo.color := clred else memo.color := clnone;
    end;
    end
    else
    begin
    if rowindex = 0 then
    begin
    // put value in the array
    if (Value <> Null) then
    begin
    // showmessage(inttostr(columnindex)+' '+ vartostr(value));
    colmin[columnindex]:= value;
    // showmessage(colmin[columnindex]);
    end;
    end;//rowindex 0
    if rowindex > 0 then
    begin
    //compare column value against array value and if less swap
    if (Value <> Null) then
    begin
    if (value < colmin[columnindex]) then colmin[columnindex]:= value;
    end;

    end;

    end;// not final
    end;//proc


    procedure frxReport1OnStartReport(Sender: TfrxComponent);
    begin
    colmin := TfrxArray.Create;
    end;

    procedure frxReport1OnStopReport(Sender: TfrxComponent);
    begin
    colmin.Free;
    end;



    begin

    end.
  • edited 5:33AM
    Thanks for the prompt response and example code. It has moved me forward.

    Just to clarify. I need to highlight individual cells, if the cell value exceeds a particular value. This 'alert' value is only known at run time.

    I would prefer to keep the event handling within my own source and not utilise the script function available within FR, if possible.

    >> make report 2 pass load values into array then set the color on the final pass.
    1) Are you referring to enabling Double Pass here or simply to pass values into a local array when they are being read, for comparison later?

    >>begin
    >>if engine.finalpass then...

    2) Can you confirm in which event the main code snippet is positioned. Is this within the frxReport1BeforePrint event or within a script event?

    3) You are directly referencing "memo", "value" and "Value" within your code snippet during each of the cycles in FinalPass. I presume value and Value are the same but what component/object do these belong to i.e I presume it's the CrossView cells. Are they only available via the FR script or can I access these from the event within the source. If so, what's the most efficient way?

    Finally, to help me with any future issues (not necessary for this issue) do you have any forum members who can provide support in C/C++?

    Thanks and I look forward to your reply

    D'Arcy
  • gordkgordk St.Catherines On. Canada.
    edited 5:33AM
    Darcy this bit should have been at the begining of the sample
    var
    colmin : TfrxArray;

    procedure Cross1OnPrintCell(Memo: TfrxMemoView; RowIndex, ColumnIndex, CellIndex: Integer; RowValues, ColumnValues, Value: Variant);

    IIRC
    not all of the properties of the crosstab matrix are exposed to the external onbefore print event, so you need to write internal scripting code to modify the cell.
    2 pass doublepass
  • edited 5:33AM
    Thanks for the update. I have had success.

    I was wondering, would it be possible to use the Tag value for each column to store an 'Alert' value, rather than entering the 'Alert' value as the 1st row in the CrossView. This Tag value could then be checked within the Cross1OnPrintCell() event instead of having to store the values in an array. I have already tried this but am having problems writing the Tag value to individual cols. I can easily assign a Tag to all cols.

    D'Arcy
  • edited 5:33AM
    Hi,
    I have resolved the issue by introducing my Alert value into the col header. Then within the OnDrawCell event I compare the value with the header alert value and set the colours accordingly.

    Thanks for the support.

    D'Arcy

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.