This is a migrated thread and some comments may be shown as answers.

GroupFooter

6 Answers 293 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Steve Taylor
Top achievements
Rank 1
Steve Taylor asked on 21 May 2007, 10:18 AM
Hi guys,

I have a standard report that includes a grouping. In the groupfooter I have a textbox that calculates the SUM of one of the columns. This is all fine but what I'd like to do is format that item, specifically it's an integer that I'd like to transform to HH:MM:SS format (i.e a Time format). So the text-box has the value of =SUM(duration) which currently shows the integer 120 and I'd like to make that look like 00:02:00 (i.e 2 minutes). I thought of using the itemdatabound event for the groupfootersection but I'm unable to get the reference of the specific textbox for that group (when I change the value in the text box I it seems to effect them all).

Is what I'm trying to achieve possible?

Thanks in advance.

6 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 21 May 2007, 12:50 PM
Hello Steve,

In a few quick steps we will show you how to achieve your goal. We have prepared a small dummy data source for the sake of demonstration and placed it in the report's constructor. You can perform these steps looking at the sample solution that we have attached for reference:


1. Add a private integer field to the report:

         int currentSum = 0;

2. Hook to the GroupHeaderSection's ItemDataBound event to nullify the sum field. This will be done at the beginning of each group:

    private void groupHeaderSection1_ItemDataBound(object sender, System.EventArgs e)
    {
        //Reset the sum for the new group
        this.currentSum = 0;
    }

3. Hook to the DetailSection's ItemDataBound event in order the add the current seconds value to the total group sum:

    private void detail_ItemDataBound(object sender, System.EventArgs e)
    {
        //Aggregate the value into the field holding the group sum
        Telerik.Reporting.Processing.DetailSection detail = (Telerik.Reporting.Processing.DetailSection)sender;
        DataRowView row = (DataRowView)detail.DataItem;
        this.currentSum += (int)row["SecondsColumn"];
    }

4. Finally, hook to the ItemDataBinding event of the TextBox in the GroupFooter, that will show the formatted value:

    private void textBox3_ItemDataBinding(object sender, System.EventArgs e)
    {
        //Before binding the textbox, set the value of its ItemDefiniton to the formatted string
        Telerik.Reporting.Processing.TextBox procTxt = (Telerik.Reporting.Processing.TextBox)sender;
        Telerik.Reporting.TextBox defTxt = (Telerik.Reporting.TextBox)procTxt.ItemDefinition;
        TimeSpan ts = new TimeSpan(0, 0, this.currentSum);
        defTxt.Value = ts.ToString();
    }

We have attached the entire solution with this sample and you can explore it in more detail. Currently, this is the only workaround for achieving your goal.

In the future we will make the Text property of the Telerik.Reporting.Processing.TextBox class writable and then this scenario will be achieved much more easily. When we do that in an upcoming Service Pack, you will be able to modify the Text property of the Telerik.Reporting.Processing.TextBox in the handler of its ItemDataBound event. In other words, you will take the already calculated value (from the =SUM(...) expression), modify it the way you like (with TimeSpan in this case), and then set it back to the TextBox. With this change, you will no longer need to calculate the value yourself by using a field and 2 additional event handlers.

Thank you for your feedback. It helped us realize this shortcoming of our API. We have awarded you with Telerik Points for that reason.
 

Regards,
Rossen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Steve Taylor
Top achievements
Rank 1
answered on 23 May 2007, 09:39 AM
Hi,
Thanks for the reply. I've tried to implement this solution but I get the following message:

Unable to cast object of type 'Telerik.Reporting.Processing.Report' to type 'Telerik.Reporting.Processing.DetailSection'.

Which is specific to the following part of the code :

Line 72:         private void detail_ItemDataBound(object sender, System.EventArgs e) 
Line 73:         { 
Line 74:             Telerik.Reporting.Processing.DetailSection detail = (Telerik.Reporting.Processing.DetailSection)sender; 
Line 75:             DataRowView row = (DataRowView)detail.DataItem; 
Line 76:             this.CurrentSum += (int)row["TotalDuration"]; 

This method is attached  to the ItemDataBound event of the Report Details pane.

Thanks in Advance




0
Steve Taylor
Top achievements
Rank 1
answered on 23 May 2007, 10:08 AM
I've solved the problem with a Try/Catch block. It seems that at some point the Report itself is calling that event and not just the Details Block.
0
Rossen Hristov
Telerik team
answered on 23 May 2007, 11:04 AM
Hi Steve,

That is very weird indeed. Unless you have attached this same event handler (detail_ItemDataBound) to the ItemDataBound event of the Report instance (this), the sender should always be a Telerik.Reporting.Processing.DetailSection.

The behavior you are getting should not be happening if the event handler method is attached only to the Detail Section's event. On our machines we cannot reproduce that and we are unable to receive a Report instance as the sender.

Can you zip and send us your Visual Studio project to support AT telerik DOT com (if possible), since we are very interested in that weird behavior? We will be glad to examine it and see what is the matter.

 
 
Kind regards,
Rossen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Daniel Botero Correa
Top achievements
Rank 1
answered on 03 Feb 2010, 03:45 PM
Hello,

I used your function textBox_DataBound but it not worked. i changed one thing and it works very good now ( im creating textoBox dynamically)

Your Function

    private void textBox3_ItemDataBinding(object sender, System.EventArgs e) 
    { 
        //Before binding the textbox, set the value of its ItemDefiniton to the formatted string 
        Telerik.Reporting.Processing.TextBox procTxt = (Telerik.Reporting.Processing.TextBox)sender; 
        Telerik.Reporting.TextBox defTxt = (Telerik.Reporting.TextBox)procTxt.ItemDefinition; 
        TimeSpan ts = new TimeSpan(0, 0, this.currentSum); 
        defTxt.Value = ts.ToString(); 
    } 

My function

    private void textBox3_ItemDataBinding(object sender, System.EventArgs e) 
    { 
        //Before binding the textbox, set the value of its ItemDefiniton to the formatted string 
        Telerik.Reporting.Processing.TextBox procTxt = (Telerik.Reporting.Processing.TextBox)sender; 
        TimeSpan ts = new TimeSpan(0, 0, this.currentSum); 
        procTxt.Value = ts.ToString(); 
    } 


if i did what you are doing, the textBox got the value of the previous textBox....

What's the difference between procTxt and procTxt.ItemDefinition ?

ok, It could help somebody, that's why i wrote it....

Bye,
Daniel BOTERO CORREA


0
Steve
Telerik team
answered on 03 Feb 2010, 04:20 PM
Hello Daniel,

You can learn about the difference between definition and processing items from the following thread: Understanding Events. This forum thread is almost 3 years old, so outdated information is expected.

Sincerely yours,
Steve
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
General Discussions
Asked by
Steve Taylor
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Steve Taylor
Top achievements
Rank 1
Daniel Botero Correa
Top achievements
Rank 1
Steve
Telerik team
Share this question
or