GridView column chooser with select all/none option

4 posts, 1 answers
  1. Edwin
    Edwin avatar
    14 posts
    Member since:
    Mar 2012

    Posted 05 Jul Link to this post

    I want to implement a column chooser and I have seen the examples here: http://docs.telerik.com/devtools/wpf/controls/radgridview/how-to/show-hide-columns-outside-of-the-radgridview.html

    However, I have not been able to find a way to implement this column chooser along with a couple of additional checkboxes: 

    "Show All":  Would make all columns on the grid visible

    "Hide All": Would make all columns on the grid invisible

    What is the best way of accomplishing this?

    Thanks.

  2. Answer
    Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    369 posts

    Posted 07 Jul Link to this post

    Hello Edwin,

    One way to achieve the desired behavior would be to add two additional checkboxes under the ListBox control (which you can replace with an ordinary ItemsControl) and handle their Checked events like so:

    <CheckBox Name="ShowAllCheckbox" Content="Show All" Grid.Row="2" Checked="ShowAllCheckbox_Checked" />
    <CheckBox Name="HideAllCheckbox" Content="Hide All" Grid.Row="3" Checked="HideAllCheckbox_Checked" />
    private void ShowAllCheckbox_Checked(object sender, RoutedEventArgs e)
    {
        foreach (var column in this.RadGridView1.Columns)
        {
            column.IsVisible = true;
        }
     
        HideAllCheckbox.IsChecked = false;
    }
     
    private void HideAllCheckbox_Checked(object sender, RoutedEventArgs e)
    {
        foreach (var column in this.RadGridView1.Columns)
        {
            column.IsVisible = false;
        }
     
        ShowAllCheckbox.IsChecked = false;
    }

    I'm attaching a sample project with the implementation. Would such an approach be suitable for your requirements?

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Edwin
    Edwin avatar
    14 posts
    Member since:
    Mar 2012

    Posted 07 Jul in reply to Dilyan Traykov Link to this post

    Thank you for your reply.  Your solution almost gets me there.  The reason I went for a ListBox is that there is a large number of columns.  With your solution, how can I implement scrolling on the list of columns?

    Thanks again.

  5. Edwin
    Edwin avatar
    14 posts
    Member since:
    Mar 2012

    Posted 07 Jul in reply to Edwin Link to this post

    Actually, I've figured it out.  Just a little tweak to your solution and it's working perfectly now. :)
Back to Top