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

Fix Grouping / Fix Sort order on grouping

1 Answer 143 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raul
Top achievements
Rank 1
Raul asked on 20 Mar 2017, 12:51 PM

Hello,

is it possible to have a predefined grouping that the user can not remove? And is it possible to have a fix sort order on that grouping - also not changeable by the user?

 

Regards,

Raul

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 23 Mar 2017, 11:18 AM
Hi Raul,

Your first requirement can be achieved by defining a ColumnGroupDescriptor and utilizing the Grouping event of the control. Note, that this event is triggered both when the user tries to group and ungroup. Thus, you should be able to benefit from it and disable the ungrouping from the UI. Please, refer to the code snippets below.
<telerik:RadGridView Grid.Row="0"
                 Name="clubsGrid"
                 ItemsSource="{Binding Clubs}"
                 Grouping="clubsGrid_Grouping"
                 GroupRenderMode="Flat"
                 AutoGenerateColumns="False"
                 Margin="5">
<telerik:RadGridView.GroupDescriptors>
    <telerik:ColumnGroupDescriptor Column="{Binding Columns[\Name\]}"/>
</telerik:RadGridView.GroupDescriptors>
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

private void clubsGrid_Grouping(object sender, GridViewGroupingEventArgs e)
        {
            if ((e.GroupDescriptor as ColumnGroupDescriptor).Column.UniqueName == "Name")
            {
                e.Cancel = true;
            }
        }

Can you please give the approach a try and let me know how it goes?

As to your second question regarding the sorting, may I kindly ask you to clarify to which sorting do you refer? Do you mean the items within each group, or the groups as a whole?​ 

Best Regards,
Stefan X1
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Raul
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or