Telerik blogs

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!

 


About the Author

Vladimir Enchev

is Director of Engineering, Native Mobile UI & Frameworks

Comments

Comments are disabled in preview mode.