Dynamic table with auto column width

edited 9:55PM in FastReport 4.0
I wish to know the best way to approach my problem.
I have a dynamic query that is set by the user at runtime. I wish to then print this query in a table in a Fast report.

I have had a look at the PrintTable demo but unfortunately it doesnt perform exactly as i require.

My query will consist of at most 6 fields. I would like to print the table in the report, but auto fit the columns based on the best fit method.
That is, based on the maximum text width of the each column, fit the table EXACTLY within 1 page (i.e. no overlap to the left or right).

So if that query has only 4 fields the stretch them accordingly to fit the width of 1 page. Similarly with a query of 5 or 6 fields.

Using the CrossView, i can set a maximum width of each column, and also autofit the contents, but if all columns are large, then the crossview spills over to the following page.

So is there any way where a Crossview/Master band can be created at runtime, and then according to the number of fields in the dataset, perform a 'BEST FIT' algorithm to adjust the column widths so they fit nicely within the width of the page?

Thanks

Comments

  • gpigpi
    edited 9:55PM
    Try to set column width in cross' OnCalcWidth event
  • edited 9:55PM
    gpi wrote: »
    Try to set column width in cross' OnCalcWidth event

    Thanks for the reply but i dont hink it is as easy as that.
    Firstly, I am unsure of how i can link a dynamically created crossview with a pascal script event handler in code (in the ReportBeforePrint event).
    Secondly, the OnCalcWidth refers to the width of the column which generated the event, and it doesnt pass any references to the other columns.

    my current code for populating the crossview looks like this:

    procedure rptBeforePrint(s : TfrxReportComponent);
    if c is TfrxCrossView then
    begin
    Cross := TfrxCrossView©;
    qryDynamic.Close;
    qryDynamic.SQL.Clear;
    qryDynamic.SQL.Add(SQL);
    qryDynamic.Open;
    i := 0;
    while not qryDynamic.Eof do
    begin
    for j := 0 to qryDynamic.Fields.Count - 1 do
    Cross.AddValue(, [qryDynamic.Fields[j].DisplayLabel], [qryDynamic.Fields[j].AsString]);
    qryDynamic.Next;
    Inc(i);
    end;
    end;

    The TFrxCrossView doesnt expose any column width or columns property.

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.