How do I remove the symbol, and the option to collapse a group on GridView?

1 Answer 101 Views
GridView
Josh Fredrickson
Top achievements
Rank 1
Josh Fredrickson asked on 22 Sep 2022, 02:16 PM | edited on 22 Sep 2022, 02:17 PM

How do I remove the symbol (up arrow) to Collapse/Expand a Group in a GridView

I want the groups to always show and always be expanded to show all items.

Thanks for any help provided!

Josh Fredrickson
Top achievements
Rank 1
commented on 22 Sep 2022, 03:10 PM

Also if possible is there a way to sort by the Group or set a Custom Order?  I want Unpaid to be on top and Paid to be on the bottom?

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 23 Sep 2022, 12:46 PM

Hi Joshua,

Thank you for the provided details.

To change the sign to text you will need to get the ExpanderItem inside the ViewCellFormatting event. In the event handler you can check if the group is expanded and then remove the default image sign and set the text property.

private void RadGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    GridGroupExpanderCellElement expanderCell = e.CellElement as GridGroupExpanderCellElement;
    if (expanderCell != null)
    {
        expanderCell.AutoSize = false;
        expanderCell.Size = new Size(70, 28);
        expanderCell.Expander.SignImage = null;
        if (e.Row.IsExpanded)
        {
            expanderCell.Expander.Text = "Collapse";
        }
        else
        {
            expanderCell.Expander.Text = "Expand";
        }
    }           
}

Keep in mind that you will need to invalidate the group to trigger the ViewCellFormatting event when the user expands/collapse the group. GroupExpanded event seems a good place to do that.

private void RadGridView1_GroupExpanded(object sender, GroupExpandedEventArgs e)
{
    e.DataGroup.GroupRow.InvalidateRow();
}

In addition, the size of the cell is hard coded for the arrow and it is too small for the text. You can increase the size of the item and move the group text to the right in the GroupSummaryEvaluate event handler.

private void RadGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
    e.FormatString = String.Format("          Group: {0}", e.Value);
}

You can check the attached project.

As for your second question, when you perform grouping, RadGridView sorts the created group rows alphabetically. This article demonstrates how to customize the groups' sort order: Sorting Groups Rows.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Josh Fredrickson
Top achievements
Rank 1
commented on 23 Sep 2022, 02:37 PM

This worked to remove the arrow "expander symbol" but there is a large spacing on the left side.

        If expanderCell IsNot Nothing Then
            expanderCell.AutoSize = False
            expanderCell.Size = New Size(0, 0)
            expanderCell.Expander.SignImage = Nothing
        End If

How do I remove that extra spacing on the left side so that  group headers and column headers are all the way on the left side?

It appears the margins and padding is set to 0 but it still has that spacing ;(

 

Dinko | Tech Support Engineer
Telerik team
commented on 26 Sep 2022, 10:21 AM

In my attached project, I wasn't able to observe such a big space on the left side. It seems to me that there is an additional setting on your side. You could modify the project to mimic your set-up. In addition, you could set a negative margin on the left side to reduce the space.

expanderCell.Margin = new Padding(-10,0,0,0);

In the attached project if you add the above code snippet you will get the following result.

 

Tags
GridView
Asked by
Josh Fredrickson
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or