How to format group title and format

2 posts, 0 answers
  1. Haibing
    Haibing avatar
    3 posts
    Member since:
    Jul 2019

    Posted 18 Jul 2019 Link to this post

    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.

     

     

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3626 posts

    Posted 22 Jul 2019 Link to this post

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