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

[Solved] ResultFormatString to hours

4 Answers 294 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Fábio Witt jagnow
Top achievements
Rank 2
Fábio Witt jagnow asked on 09 Nov 2010, 01:13 PM
Hey im using an Aggregate Function in my Grid and its working just nice. What i want is for the totals to display like this:
38:00 (in hours and minutes). I've searched in the forum but didn't found any clue that could help me.

<telerik:GridViewDataColumn.AggregateFunctions>
    <telerik:SumFunction ResultFormatString="{}{0:G}" SourceField="MyField"/>                                 
</
telerik:GridViewDataColumn.AggregateFunctions>

If anybody could help me i'd appreciate.

4 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 09 Nov 2010, 01:59 PM
Hello Fábio Witt jagnow,

 What is the type of MyField? DateTime, TimeSpan, Integer, etc.?

All the best,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Fábio Witt jagnow
Top achievements
Rank 2
answered on 09 Nov 2010, 02:06 PM
Hi my field is nullable decimal.

public Decimal? MyField { get; set; }

We use a mask to display that number in hours in the GridViewColumn.
I've attached a screen of my issue.
0
Yavor Georgiev
Telerik team
answered on 09 Nov 2010, 05:05 PM
Hello Fábio Witt jagnow,

 What sort of mask do you use? Can you post some pertinent code? The problem is that the "{0:G}" format string applies to DateTime values, not to decimal. You can check this blog post for more information on string formatting in .NET.

Kind regards,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Fábio Witt jagnow
Top achievements
Rank 2
answered on 09 Nov 2010, 07:33 PM
Sorry if i made myself not clear, but i've achieved the solution with some more search.
The result format string was there just beacuse i was testing.
I've got what i wanted with Custom Aggregate Function

The example

I'll post my code here just if anyone needs it.

public class tTimeSumFunction : EnumerableSelectorAggregateFunction
{
    protected override string AggregateMethodName
    {
        get { return "TimeSum"; }
    }
 
    protected override System.Type ExtensionMethodsType
    {
        get { return typeof(tTimeSumMethods); }
    }
}
 
public static class tTimeSumMethods
{
    public static string TimeSum<T>(IEnumerable<T> source, Func<T, Decimal?> selector)
    {
        IEnumerable<double> values = from i in source select Convert.ToDouble(selector(i));
        return tclean.NumToTime(values.Sum().ToString());
    }
}
*That tclean.NumToTime is a function that formats a number to time.
<telerik:GridViewDataColumn BindingPath="MyField"IsReadOnly="True">
    <telerik:GridViewDataColumn.AggregateFunctions>
        <local:tTimeSumFunction SourceField="MyField" Caption="Total" />
    </telerik:GridViewDataColumn.AggregateFunctions>
</telerik:GridViewDataColumn>
And there is the picture of the result i wanted.
Tags
GridView
Asked by
Fábio Witt jagnow
Top achievements
Rank 2
Answers by
Yavor Georgiev
Telerik team
Fábio Witt jagnow
Top achievements
Rank 2
Share this question
or