Change total summary row style in GridView

4 posts, 0 answers
  1. Alex
    Alex avatar
    2 posts
    Member since:
    Nov 2013

    Posted 09 Dec 2013 Link to this post

    Hello!
    I use RadGridView with grouping (with subtotal summary rows) and with total summary row at the end of the gridview.
    I need to change text style only in total summary row. I've tried to use ViewCellFormatting event
    private void gvProducts_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
            {
                if (e.CellElement is GridSummaryCellElement)
                {
                    e.CellElement.TextAlignment = ContentAlignment.BottomRight;
                    e.CellElement.Font = new Font(e.CellElement.Font, FontStyle.Bold);
                }
            }
    But this code changes text style in each summary row. Could you help me, how can I understand is it a subtotal summary row or the last total summary row? Thank you in advance.
  2. Ralitsa
    Admin
    Ralitsa avatar
    190 posts

    Posted 12 Dec 2013 Link to this post

    Hi Alex, 

    Thank you for contacting us. 

    The total summary cell has a Group property which is null. You can check this property and apply suitable formatting. Please take a look at the following sample code which demonstrates you how to customize the total summary cell: 
    Font totalRowsFont;
     
    public Form1()
    {
        InitializeComponent();
     
        totalRowsFont = new Font("Segoe UI", 9.0f, FontStyle.Bold);
    }
     
    private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        if (e.CellElement.RowInfo.Group == null && e.CellElement is GridSummaryCellElement)
        {
            e.CellElement.ForeColor = Color.Red;
            e.CellElement.TextAlignment = ContentAlignment.BottomRight;
            e.CellElement.Font = totalRowsFont;
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.TextAlignmentProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.FontProperty, ValueResetFlags.Local);
        }
    }

    In order to prevent applying the formatting to other columns' cell elements all customization should be reset for the rest of the cell elements when use events like ViewCellFormatting, ViewRowFormatting, CellFormatting

    You can also note that we are creating a single Font object only once globally. This is done for performance purposes. Creating a Font object is a heavy task and the formatting events are fired numerous times, so operations like font creation should occur outside the formatting events scope.

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

    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 >>
  3. Alex
    Alex avatar
    2 posts
    Member since:
    Nov 2013

    Posted 12 Dec 2013 Link to this post

    Thank you for your help. It worked perfect for me. And thanks for performance advice.
  4. Ralitsa
    Admin
    Ralitsa avatar
    190 posts

    Posted 16 Dec 2013 Link to this post

    Hi Alex,

    I am glad to hear that everything works fine for you now. Do not hesitate to write back if you have additional questions.

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