Programmatic Grouping - GroupDescriptor

6 posts, 0 answers
  1. Jacob
    Jacob  avatar
    22 posts
    Member since:
    Apr 2016

    Posted 09 May Link to this post

    Hello Telerik,

     

    I am trying to pre-group my Gridview on the start of the page (page load)

    so i saw a very interesting documentation you have called "programmatic grouping", which has the following block of code i would need to use inside my XAML

    <telerik:GroupDescriptor Member="Country"
    SortDirection="Ascending"
    DisplayContent="Country Group" />

     

    My question is: where exactly is this GroupDescriptor? It doesn't seem to recognize the tag at all. Can you provide me a sample or something that uses it? I couldn't find one in your demos tool.

     

    thank you.

  2. Jacob
    Jacob  avatar
    22 posts
    Member since:
    Apr 2016

    Posted 11 May in reply to Jacob Link to this post

    looking forward to hear from you

    thank you!

  3. UI for WPF is Visual Studio 2017 Ready
  4. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 11 May Link to this post

    Hello Jacob,

    I'm attaching a sample project with the two approaches described in the article.

    1) The code-behind approach can be placed in the constructor of your Window and be used similarly to:

    public MainWindow()
    {
        InitializeComponent();
     
        GroupDescriptor descriptor = new GroupDescriptor();
        descriptor.Member = "Name";
        descriptor.SortDirection = ListSortDirection.Ascending;
        this.radGridView.GroupDescriptors.Add(descriptor);
    }

    2) The same can be achieved using the following XAML code:

    <telerik:RadGridView Name="radGridView">
        <telerik:RadGridView.GroupDescriptors>
            <telerik:GroupDescriptor Member="Name" SortDirection="Ascending" />
        </telerik:RadGridView.GroupDescriptors>
    </telerik:RadGridView>

    I hope you find this helpful.

    Regards,
    Dilyan Traykov
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  5. Jacob
    Jacob  avatar
    22 posts
    Member since:
    Apr 2016

    Posted 11 May in reply to Dilyan Traykov Link to this post

    This works! But I could swear the telerik:RadGridView.GroupDescriptors tag was not being recognizing before.

    anyhow, thank you very much. issue solved!

  6. Jacob
    Jacob  avatar
    22 posts
    Member since:
    Apr 2016

    Posted 29 Jun Link to this post

    Hello again,

    For now I just need to change the header of my group on fly

    I see it comes after the field's name and as you can see in the attached picture, the header is not very user friendly

    How can I change it in the codebehind or viewmodel?

     

    Here is the code I use to create the groupdescriptor

    private void Page_Loaded(object sender, RoutedEventArgs e)
    {
        systemSettingsViewModel = this.DataContext as SystemSettingsViewModel;
        systemSettingsViewModel?.GetAllSystemSettingsDTOs();
        GroupDescriptor descriptor = new GroupDescriptor();
     
        // clear all filters and groupings from an earlier visit!
        CustGridview.ClearFiltersSortingGrouping();
        descriptor.Member = "SettingGroupTranslated";
        descriptor.MemberType = typeof(string);
        descriptor.SortDirection = ListSortDirection.Ascending;
        CustGridview.GroupDescriptors.Add(descriptor);
     
    }

  7. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 30 Jun Link to this post

    Hello Jacob,

    You can achieve this by setting the DisplayContent property of the GroupDescriptor as demonstrated in our Programmatic Grouping article:

    descriptor.DisplayContent = "Custom Header";

    Please let me know if this works for you.

    Regards,
    Dilyan Traykov
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready