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

How to format group title and format

1 Answer 405 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Haibing
Top achievements
Rank 1
Haibing asked on 18 Jul 2019, 07:32 AM

I want to format group row's title with the following requirements:

 

1. Change the group row's default title:

    I use the GroupSummaryEvaluate event, but I could not get the grouping  column's header text,from the example, I could only the the column's name(e.SummaryItem.Name). I hope to get the column's header text to continue my work.

2. Change the group row's background color or foreground color

   I hope the change the default color of the group row

3. Add simple controls to the group row. e.g. I want to add an label with some red text to the group.

 

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 Jul 2019, 10:06 AM
Hello, Haibing, 

Indeed, the GroupSummaryEvaluate event is the appropriate place to control what text exactly to be shown for the group headers. The GroupSummaryEvaluationEventArgs.Context gives you access to the GridViewGroupRowInfo. You have to cast to it in order to get the HeaderText property.

private void radGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
    GridViewGroupRowInfo groupRow = e.Context as GridViewGroupRowInfo;
    if (groupRow !=null)
    {
        Console.WriteLine(groupRow.HeaderText);
    }
}

The ViewRowFormatting event allows you to customize not only the data rows but also the system rows. The following code snippet demonstrates how to make the group rows red in color: 

private void radGridView1_ViewRowFormatting(object sender, RowFormattingEventArgs e)
{
    if (e.RowElement.RowInfo is GridViewGroupRowInfo)
    {
        e.RowElement.DrawFill = true;
        e.RowElement.GradientStyle = GradientStyles.Solid;
        e.RowElement.BackColor = Color.Red;
    }
    else
    {
        e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
        e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
        e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty , ValueResetFlags.Local);
    }
}

As to the question about creating custom group cells and adding custom elements to them, I would recommend you to have a look at the following help article which demonstrates a sample approach in its Custom group cell examplehttps://docs.telerik.com/devtools/winforms/controls/gridview/cells/creating-custom-cells

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Haibing
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or