Is there a way to perform custom formatting on a field?

Posted by: toddniec on 14 September 2017, 7:13 pm EST

    • Post Options:
    • Link

    Posted 14 September 2017, 7:13 pm EST

    [activereports_archive]in my project some dataset columns have numeric types that must go through complex formatting that cannot be done with the built-in .NET ToString() type formats.

    Up until now I have been doing the formatting when creating the dataset, storing formatted strings in the columns instead of the numeric values.

    However, that is going to cause problems as the strings cannot be sorted or used in aggregate math operations so I would like to go back to storing the numerical values in the dataset. But then I need a way to format the values at “print time” Is there a way to run .net -based “formatting code” that can render the value stored in the data set column to the desired value to be printed?

    I am thinking of a mechanism like the .NET winforms databinding’s events to format a property before it is shown in a control.

    thanks.[/activereports_archive]

  • Posted 14 September 2017, 7:13 pm EST

    [activereports_archive]Hi,

    Which type of Reports are you using (Section or Page Reports) and what is the format that you wish to set on the numerical values?

    If you’re using SectionReports, then the TextBox control has an OutputFormat property for such purposes (http://arhelp.grapecity.com/webhelp/AR10/index.html#GrapeCity.ActiveReports.v10~GrapeCity.ActiveReports.SectionReportModel.TextBox~OutputFormat.html)

    or if you’re using a PageReport, you can use the TextBox’s Format property(http://arhelp.grapecity.com/webhelp/AR10/index.html#TextBox.html)

    Let me know if it helps or if you need any other help

    [/activereports_archive]

  • Posted 14 September 2017, 7:13 pm EST

    [activereports_archive]>> Which type of Reports are you using (Section or Page Reports)

    Currently section, but I may need to support page reports too.

    what is the format that you wish to set on the numerical values?

    Its not a standard .net format that is supported by the .net library in any way.

    The formatting process looks at system settings and user preferences to determine the unit (inches, mm, etc) the value should be expressed in. The numerical format (fractional/decimal) and the level of precision (number of decimal digits, the maximum denominator of the fraction) and other factors. This formatting is all done in C# code, but not handled by a simple format string.

    The values to be formatted are in fields, not text boxes. I beleive those are different, right?[/activereports_archive]

  • Posted 14 September 2017, 7:13 pm EST

    [activereports_archive]For SectionReports, you can handle the Detail Section’s format event in code, apply formatting to the field values and then set them in the TextBox. Something like :

    [csharp]private void detail_Format(object sender, EventArgs e)

    {

    var val = this.Fields[“UnitPrice”].Value.ToString();

    //apply formatting to val

    textBox2.Text = “$” + val;

    }[/csharp]

    Hope it helps[/activereports_archive]

  • Posted 10 August 2019, 6:25 am EST

    Hello, since when can Fields data be used outside the FetchData event? In which events can Fields data be used now?

    a greeting

  • Posted 12 August 2019, 1:46 am EST

    Hello,

    Sorry, I could not understand your exact question. Could you please explain the detail.

    “Fields” data can use outside the event when you have to format or do some changes in the data. You only use the Field data in the “Format” event of the section.

    Please refer to the following link for more information on the events:

    https://help.grapecity.com/activereports/webhelp/AR13/webframe.html#ReportEvents.html

    Hope it helps.

    Thanks.

  • Posted 17 August 2019, 6:42 am EST

    Hi this is what the documentation says:

    FetchData

    This event is raised every time a new record is processed. The FetchData has an EOF parameter indicating whether the FetchData event should be raised. This parameter is not the same as the Recordset’s EOF property and is defaulted to True. When working with bound reports (reports using a DataControl), the EOF parameter is automatically set by the report; however, when working with unbound reports this parameter needs to be controlled manually.

    Use the FetchData event with unbound reports to set the values of custom fields that were added in the DataInitialize event or with bound reports to perform special functions, such as combining fields together or performing calculations. The FetchData event should not have any references to controls on the report.

    If you need to use a value from a Dataset with a control in the Detail section, set a variable in the FetchData event and use the variable in the section’s Format event to set the value for the control. Please note that this method of setting a variable in the FetchData event and using it to set a control’s value is only supported in the Detail_Format event.

    Also use the FetchData event to increment counters when working with arrays or collections.

    According to this information in the format detail event, the Fields collection cannot be used directly.

  • Posted 19 August 2019, 5:13 am EST

    Hello Jose,

    Yes, you can use the “Fields” data outside the event by setting a variable in the FetchData event and use the variable in the section’s Format event to set the value for the control.

    Request to please confirm what is your actual requirement in the report. When do you want to fetch the “Fields” data and what type of operation you want to perform?

    This will be very helpful for us.

    Thanks.

  • Posted 26 August 2019, 3:26 am EST

    Hi Mohitg,

    What I need is to know how I can safely access the last collection of fields read in the detail_format, groupheader_format and pageheader_format events.

    Thanks.

  • Posted 29 August 2019, 3:37 am EST

    Hi Mohitg,

    I don’t know if I explained myself well in the last message sent since I don’t get an answer

    Thanks.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels