4 Answers, 1 is accepted
0
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
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?
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());
}
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
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:
I hope this will help. Do not hesitate to write back with further questions.
Regards,
Ralitsa
Telerik
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