Convert GridviewSummaryItem from Int to time format hh:mm:ss

1 Answer 167 Views
GridView
Joswhar
Top achievements
Rank 1
Iron
Joswhar asked on 24 Jun 2021, 10:07 AM

Hi.

I have this:

GridViewSummaryItem Duracao = new GridViewSummaryItem();
Duracao.Name = "Duração";
Duracao.FormatString = "{0}";
Duracao.AggregateExpression = "(sum(T_H))";

sum(T_H) it's the sum of times in seconds. I need show the result in time format (hh:mm:ss)

How i can do it? help please.

i'm program in C#.

Thank you.

1 Answer, 1 is accepted

Sort by
1
Joswhar
Top achievements
Rank 1
Iron
answered on 24 Jun 2021, 11:44 AM

Hi,

I finally did it.

I delete the line Duracao.FormatString = "{0}";  and add the event GroupSummaryEvaluate with the next code:

private void dgProducaoGeral_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
            if (e.SummaryItem.Name == "Duração")
            {
                Int32 Segundos=0;
                foreach (GridViewRowInfo row in dgProducaoGeral.ChildRows)
                {
                    Segundos += Int32.Parse(row.Cells["T_H"].Value.ToString());
                }

                Int32 horas = Segundos / 3600;
                Int32 minutos = ((Segundos) - horas * 3600) / 60;
                Int32 segundos = Segundos - (horas * 3600 + minutos * 60);
            
                string result = horas.ToString("D2") + ":" + minutos.ToString("D2") + ":" + segundos.ToString("D2");
                e.FormatString = String.Format("{1}", e.Value, result);
            }

}

This works perfectly

Add an image of the code and the result in the RadGridView and hope this information helps other programmers with the same problem.

Stoyan
Telerik team
commented on 25 Jun 2021, 09:55 AM

Hello Joswhar,

I am glad that you managed to find yourself the answer.

If you need more assistance we will be happy to help.

Have a nice day!

Regards,StoyanProgress Telerik

Tags
GridView
Asked by
Joswhar
Top achievements
Rank 1
Iron
Answers by
Joswhar
Top achievements
Rank 1
Iron
Share this question
or