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

Summary rows cell value change

1 Answer 81 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ales
Top achievements
Rank 1
Ales asked on 28 Mar 2012, 11:39 AM
Hi,

i have for example in summary row value :

A) 1, 00
B) 1 000, 00
C) 1 000 000, 00

but i need to display in this cell
A) 1,00
B) 1,00 K
C) 1,00 M

Know somebody how to do that ?
Thanks for all answers

best regards
AB

1 Answer, 1 is accepted

Sort by
0
Accepted
Ivan Petrov
Telerik team
answered on 30 Mar 2012, 03:43 PM
Hello Ales,

Thank you for writing.

You can use the GroupSummaryEvaluate event to change the text displayed in the summary cells. Here is a basic implementation of your case:
private void radGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
  if (!(e.Context is GridViewSummaryRowInfo))
  {
    return;
  }
 
  e.Value = this.FormatSummaryString((decimal)e.Value);
}
 
private string FormatSummaryString(decimal value)
{
  string result = String.Format("{0:N2}", value);
  result = result.Replace(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberGroupSeparator, "");
 
  int index = result.LastIndexOf("000000");
  if (index > -1)
  {
    result = result.Remove(index, 6);
    result += " M";
  }
 
  index = result.LastIndexOf("000");
  if (index > -1)
  {
    result = result.Remove(index, 3);
    result += " K";
  }
 
  return result;
}

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

Regards,
Ivan Petrov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Ales
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Share this question
or