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

Group by column but don't allow user to change it

4 Answers 202 Views
GridView
This is a migrated thread and some comments may be shown as answers.
strombringer
Top achievements
Rank 2
strombringer asked on 02 Sep 2009, 07:40 AM
I was just about to send a support ticket when I found the solution to a request for the GridView layout that I'd like to share:

The requested layout:
- The grid is grouped by one column by default
- The user can change the sort order of all columns
- The user can't change the grouping of the grid

Solution:
- Add the GroupByExpression for the column in code or through the designer
- RadGridView.EnableGrouping == true (if false, the grouping header is not shown)
- RadGridView.MasterGridViewTemplate.AllowDragToGroup == false (no more columns can be added to the grouping header)
- set the "AllowGroup" property of the column in the grouping header to "false" (the user can't remove the grouping column from the header)

Perhaps someone else finds this useful.

EDIT:
I missed, that the "column button" in the grouping header contains a "X" to remove the group. This Close Button is still enabled and the user can remove the group. Any suggestions?

4 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay
Telerik team
answered on 04 Sep 2009, 12:30 PM
Hi strombringer,

Thank you for sharing your approach with the community. I am updating your Telerik points for it.

In order to remove the close ("X") button, you need to implement the following logic in your project:
GridGroupHeaderItemsContainer container = ((GridTableElement)this.radGridView1.GridElement).HeaderElement.GroupPanel.GroupHeaderList.Items[0] as GridGroupHeaderItemsContainer;  
if (container != null)  
{  
    for (int index = 0; index < container.Children.Count; index++)  
    {  
        GridGroupHeaderItem item = container.Children[index] as GridGroupHeaderItem;  
        item.Children[2].Visibility = ElementVisibility.Collapsed;  
    }  

As you can see, I am taking all the available GridGroupHeaderItems (group buttons) and then I am collapsing the third child of their elements hierarchy (the close button).

I hope this helps. If you have additional questions, feel free to contact me.

Best wishes,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Nadia Sangiovanni
Top achievements
Rank 1
answered on 05 Dec 2013, 09:08 PM
Hi Support,

I try to implement the proposed solution to remove the "X" on the button of the column in the group header. The "HeaderElement" is not available in the property of a GridTableElement.

Is there any way I can remove the "X" button?

Regards,
Nadia
0
Nikolay
Telerik team
answered on 10 Dec 2013, 01:26 PM
Hello Nadia,

In our latest versions you can remove the "X" buttons from the group items using the code snippet below:
TemplateGroupsElement templateGroups = (TemplateGroupsElement)radGridView1.GridViewElement.GroupPanelElement.PanelContainer.Children[0];
foreach (GroupElement gElement in templateGroups.Children)
{
    foreach (GroupFieldElement gFieldElement in gElement.GroupingFieldElements)
    {
        gFieldElement.RemoveButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
    }
}

I hope this will help you.

Regards,
Nikolay
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
Nadia Sangiovanni
Top achievements
Rank 1
answered on 10 Dec 2013, 08:43 PM
Tank you Nikolay,

Your solution work perfectly!

Regards,
Nadia
Tags
GridView
Asked by
strombringer
Top achievements
Rank 2
Answers by
Nikolay
Telerik team
Nadia Sangiovanni
Top achievements
Rank 1
Share this question
or