The columns in the GridControl prepared by the showfooter method there are hours like you see in the picture I want to sum the columns of those hours how do I do it?
Thnx for your help
The columns in the GridControl prepared by the showfooter method there are hours like you see in the picture I want to sum the columns of those hours how do I do it?
Thnx for your help
You can use the TimeSpan
class to parse strings in the format hours:minutes
, and can add them together in a loop. For example:
private static void Main()
{
var colTimes = new List<string>
{
"01:00", "02:10", "07:40", "03:45", "02:45"
};
var totalTime = new TimeSpan(0, 0, 0);
foreach(string colTime in colTimes)
{
totalTime = totalTime.Add(TimeSpan.Parse(colTime));
}
Console.WriteLine($"Times: {string.Join(", ", colTimes)}");
Console.WriteLine($"\nThe total is: {totalTime.ToString(@"hh\:mm")}");
GetKeyFromUser("\nDone!\nPress any key to exit...");
}
Or you could do a Linq-based alternative and avoid the loop:
var totalTime = new TimeSpan(colTimes.Sum(time => TimeSpan.Parse(time).Ticks));
Output