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

5 posts, 1 answers
  1. strombringer
    strombringer avatar
    5 posts
    Member since:
    Mar 2008

    Posted 02 Sep 2009 Link to this post

    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?
  2. Answer
    Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 04 Sep 2009 Link to this post

    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.
  3. Nadia Sangiovanni
    Nadia Sangiovanni avatar
    38 posts
    Member since:
    Apr 2010

    Posted 05 Dec 2013 Link to this post

    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
  4. Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 10 Dec 2013 Link to this post

    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 >>
  5. Nadia Sangiovanni
    Nadia Sangiovanni avatar
    38 posts
    Member since:
    Apr 2010

    Posted 10 Dec 2013 Link to this post

    Tank you Nikolay,

    Your solution work perfectly!

    Regards,
    Nadia
Back to Top