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

Change total summary row style in GridView

3 Answers 193 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 09 Dec 2013, 01:32 PM
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.

3 Answers, 1 is accepted

Sort by
0
Ralitsa
Telerik team
answered on 12 Dec 2013, 11:14 AM
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 >>
0
Alex
Top achievements
Rank 1
answered on 12 Dec 2013, 03:01 PM
Thank you for your help. It worked perfect for me. And thanks for performance advice.
0
Ralitsa
Telerik team
answered on 16 Dec 2013, 01:23 PM
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 >>
Tags
GridView
Asked by
Alex
Top achievements
Rank 1
Answers by
Ralitsa
Telerik team
Alex
Top achievements
Rank 1
Share this question
or