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

GridView column chooser with select all/none option

3 Answers 151 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Edwin
Top achievements
Rank 1
Edwin asked on 05 Jul 2016, 09:54 PM

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.

3 Answers, 1 is accepted

Sort by
0
Accepted
Dilyan Traykov
Telerik team
answered on 07 Jul 2016, 11:15 AM
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.
0
Edwin
Top achievements
Rank 1
answered on 07 Jul 2016, 03:15 PM

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.

0
Edwin
Top achievements
Rank 1
answered on 07 Jul 2016, 03:51 PM
Actually, I've figured it out.  Just a little tweak to your solution and it's working perfectly now. :)
Tags
GridView
Asked by
Edwin
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Edwin
Top achievements
Rank 1
Share this question
or