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

how can I use row summery in datagridview to show the sum of a time format column

4 Answers 39 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Maryam
Top achievements
Rank 1
Maryam asked on 23 Feb 2014, 09:36 AM
I added some maskbox column to my datagrid.the mask type is time. I want the row summery shows sum of times in each column

4 Answers, 1 is accepted

Sort by
0
Ralitsa
Telerik team
answered on 26 Feb 2014, 08:44 AM
Hi Mary,

Thank you for contacting us. 

You need to subscribe to the GroupSummaryEvaluate event and implement own logic how to sum the time. The GroupSummaryEvaluate event is fired when evaluation of group summary is undergoing. 

I attached you a sample demo project wwhich demonstrates you implementation of summary row. I use TimeSpan variable to sum of the time.

You can find useful the article for TimeSpan Structure from MSDN and Summary Rows from our documentation. 

Should you have further questions, I would be glad to help.

Regards,
Ralitsa
Telerik
0
Maryam
Top achievements
Rank 1
answered on 02 Mar 2014, 06:14 AM
Hi Ralista. thanks for your help.I try this code but I don't Know why it doesn't work!!!
my GridView Columns are type of string and I parse them to TimeSpan when I want Calculate sum Of them.What's the problem?

0
Maryam
Top achievements
Rank 1
answered on 02 Mar 2014, 06:17 AM
GridViewSummaryItem summeyItem = new GridViewSummaryItem("OvrExit", "{0}", GridAggregateFunction.Count);
            GridViewSummaryRowItem summeryrowitem = new GridViewSummaryRowItem();
            summeryrowitem.Add(summeyItem);
            this.dataGridView1.SummaryRowsBottom.Add(summeryrowitem);
            this.dataGridView1.GroupSummaryEvaluate += dataGridView1_GroupSummaryEvaluate;

 private void dataGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
        {
            MasterGridViewTemplate table = (MasterGridViewTemplate)sender;
            TimeSpan sum = TimeSpan.Zero;
            {
                string g = row.Cells[e.SummaryItem.Name].Value.ToString();
                if (!string.IsNullOrEmpty(g))
                {
                    TimeSpan temp = TimeSpan.Parse(g);
                    sum+=temp;
                }
            }
            e.FormatString = String.Format("Sum is:", sum.ToString());
        }
0
Ralitsa
Telerik team
answered on 04 Mar 2014, 05:04 PM
Hi Mary,

Thank you for contacting us. 

The code works correctly. In your code example there is a placeholder omitted in the string format and that is why the sum of time is not displayed in the summary row. Please use this code snippet: 
//fixed code
e.FormatString = String.Format("Sum is: {0}", sum.ToString());

I hope this will help. Do not hesitate to write back with further questions.

Regards,
Ralitsa
Telerik
Tags
GridView
Asked by
Maryam
Top achievements
Rank 1
Answers by
Ralitsa
Telerik team
Maryam
Top achievements
Rank 1
Share this question
or