Format string summary row

5 posts, 1 answers
  1. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 05 Jan 2014 Link to this post

    I have created a summary row like this:

    private void radGridView1_Initialized(object sender, EventArgs e)
           {
               this.radGridView1.SummaryRowsBottom.Add(new GridViewSummaryRowItem(new GridViewSummaryItem[]{
               new GridViewSummaryItem("Balance", "{0}", GridAggregateFunction.Sum)}));
               this.radGridView1.MasterTemplate.ShowTotals = true;
               this.radGridView1.MasterView.SummaryRows[0].PinPosition = PinnedRowPosition.Top;
           }
     and I have formatted the text in this way:
    private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
        {
               
            if (e.CellElement is GridSummaryCellElement)
            {
                e.CellElement.TextAlignment = ContentAlignment.MiddleRight;
                Font summaryFont = new Font("Segoe", 9, FontStyle.Bold);
                  
                e.CellElement.Font = summaryFont;
            }
        }
    How can I set the format string like this {0:R #.##,##}?
  2. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 07 Jan 2014 Link to this post

    Problem solved.
    new GridViewSummaryItem("Balance", "{0:R #.###,##}", GridAggregateFunction.Sum)}));
  3. Answer
    Ralitsa
    Admin
    Ralitsa avatar
    190 posts

    Posted 07 Jan 2014 Link to this post

    Hi Felice,

    I am glad to hear that you find how to set the format string.  You can take a look at our article Summary Rows where it is described how to use and customize the summary rows in the RadGridView

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

    Regards,
    Ralitsa
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  4. George
    George avatar
    12 posts
    Member since:
    Feb 2014

    Posted 20 Sep 2017 in reply to Ralitsa Link to this post

    I have used this code  Dim AvgResponseTime As New GridViewSummaryItem("ResponseTime", "{0: #.#}", GridAggregateFunction.Avg) and works . However if the value is 0,9 does not display the zero.
  5. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3530 posts

    Posted 22 Sep 2017 Link to this post

    Hello, George, 

    Thank you for writing.  

    The "#" symbol indicates an optional digit or space. That is why the value 0.9 is display as .9. You can replace the "#" symbol with "0​" indicating required digits: 
    Dim summaryItem As New GridViewSummaryItem("UnitPrice", "{0: 0.0}", GridAggregateFunction.Min)
    Dim summaryRowItem As New GridViewSummaryRowItem()
    summaryRowItem.Add(summaryItem)
    Me.RadGridView1.SummaryRowsTop.Add(summaryRowItem)


    Alternatively, you can use the GroupSummaryEvaluate event which is fired after a summary item is calculated and before the summary row is displayed. You can use it to apply custom formatting to the summary row.

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top