-3

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

enter image description here

Rufus L
  • 36,127
  • 5
  • 30
  • 43

1 Answers1

0

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

![enter image description here

Rufus L
  • 36,127
  • 5
  • 30
  • 43