How To: Column chooser for RadGridView for Silverlight and WPF

by Vladimir Enchev | Comments 6

I’ve made small demo on how to create column chooser for any RadGridView in few very simple steps:

 

1. Add new ChildWindow:
ColumnChooser1

 

2. Define following XAML for the child window:

<Grid x:Name="LayoutRoot" Margin="2">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition />
    </Grid.RowDefinitions>
    <TextBlock Text="Available columns:" />
    <ListBox ItemsSource="{Binding Columns}" Grid.Row="1">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <CheckBox Content="{Binding Header}" IsChecked="{Binding IsVisible, Mode=TwoWay}" />
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

 

3. Set DataContext for the child window to be desired RadGridView:

public partial class ColumnChooser : ChildWindow
{
    public ColumnChooser(RadGridView grid)
    {
        InitializeComponent();

        this.DataContext = grid;
    }
}

 

4. Create and show the child window:

private void Button_Click(object sender, RoutedEventArgs e)
{
    new ColumnChooser(RadGridView1).Show();
}

 

The result:

ColumnChooser2

 

Enjoy!

 

,
Senior Technical Architect

6 Comments

Prad
I have <telerik:GridViewSelectColumn /> in the Grid. How do we get rid of this header in column chooser?

 

Neel
Hi...

I'm very new to Silverlight... I need to do some thing similar to what you have done in the above example but the difference is in the child window i want to show a grid with 3 columns...
1. 1st column will have list of column headers
2. Hide - this will have check box to hide and show the column as shown above
3. Sum - this will determine whether to show Sum of the column values or not...

Then  I need to save this information as a xml in database...

Can you please show me an example how can I use a radgridview to implement the same..

Thanks
Neel
Hi...

I'm very new to Silverlight... I need to do some thing similar to what you have done in the above example but the difference is in the child window i want to show a grid with 3 columns...
1. 1st column will have list of column headers
2. Hide - this will have check box to hide and show the column as shown above
3. Sum - this will determine whether to show Sum of the column values or not...

Then  I need to save this information as a xml in database...

Can you please show me an example how can I use a radgridview to implement the same..

Thanks
Neel
Hi...

I'm very new to Silverlight... I need to do some thing similar to what you have done in the above example but the difference is in the child window i want to show a grid with 3 columns...
1. 1st column will have list of column headers
2. Hide - this will have check box to hide and show the column as shown above
3. Sum - this will determine whether to show Sum of the column values or not...

Then  I need to save this information as a xml in database...

Can you please show me an example how can I use a radgridview to implement the same..

Thanks
shenthil
It was really informational. Thanks
jfk
How would you get this to work when using the header templates in order to wrap header text?

Comments

  1.    
      
      
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)
Read more articles by Vladimir Enchev - or - read latest articles in Developer Tools
Product Families