Summary rows cell value change

2 posts, 1 answers
  1. Ales
    Ales avatar
    5 posts
    Member since:
    Dec 2011

    Posted 28 Mar 2012 Link to this post

    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
  2. Answer
    Ivan Petrov
    Admin
    Ivan Petrov avatar
    705 posts

    Posted 30 Mar 2012 Link to this post

    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 >>
Back to Top