C# script in group sum field

Posted by: patrick.nunn on 26 June 2020, 1:23 am EST

    • Post Options:
    • Link

    Posted 26 June 2020, 1:23 am EST

    I have a section report. In this report I need a list of times in the format “HH:mm”. I then need subtotals and totals also in this format.

    I tried passing this data in as Time with the OutputFormat property set to “HH:mm” but this was throwing exceptions as it wasn’t a valid conversion from a TimeSpan.

    So I found a workaround where I use a c# script in the DataField:

    =((int)(TimeInMins / 60)).ToString("D2") + ":" + ((int)(TimeInMins % 60)).ToString("D2")
    

    This is fine for the individual rows but on the subtotals and totals it only returns the value of the last row in that format.

    Could somebody point me in the right direction?

  • Posted 28 June 2020, 5:49 pm EST

    Hello,

    You can use the summary function on the Textbox in the GroupFooter and Report Footer. After that, you can change the format of the TextBox in Format event of the “GroupFooter” and “ReportFooter” as follow:

    public void GroupFooter1_Format()
    {
    	
    	this.TextBox1.Value = (int.Parse(this.TextBox1.Text) / 60).ToString("D2") + ":" + (int.Parse(this.TextBox1.Text) % 60).ToString("D2");
    }
    
    public void ReportFooter1_Format()
    {
    	this.TextBox2.Value = (int.Parse(this.TextBox2.Text) / 60).ToString("D2") + ":" + (int.Parse(this.TextBox2.Text) % 60).ToString("D2");
    }
    

    Please refer to the attached report for implementing the same.

    Thanks,

    Mohit

    testformat.zip

Need extra support?

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

Learn More

Forum Channels