I am trying to hide two colomn on check of checkbox i used telerk radgrid control for it. grid contains five colomn ID ,FName , LName,MobileNo,branch .When check box is checked on want to hide ID and name colomn please give hint for that my code is as follow
C# code: class MainWindowViewModel {
public MainWindowViewModel()
{
EmpList = ListOfEmpInfo();
}
private ObservableCollection<EmpInfo> ListOfEmpInfo()
{
return new ObservableCollection<EmpInfo>()
{
new EmpInfo(){ ID=1, City ="Pune" , FirstName ="Rahul" , LasttName ="Rathod", MobileNumber =123},
new EmpInfo(){ ID=2, City ="Mumbai" , FirstName ="Mahesh" , LasttName ="Yogaa", MobileNumber =456},
new EmpInfo(){ID=3, City ="Jalna" , FirstName ="Ganesh" , LasttName ="Kapadia", MobileNumber =178923}
};
}
public ObservableCollection<EmpInfo> EmpList
{
get;
set;
}
}
<Grid Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="500"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<CheckBox Content="Hide Show" IsChecked="{Binding IsVisible}" Height="40" Grid.Column="2"></CheckBox>
<telerik:RadGridView x:Name="radGridView" ItemsSource="{Binding EmpList}"
Grid.Column="1"
Margin="10,0,0,0" />
</Grid>
You can see a working solution here: WPF Control TabItem visibility from a checkbox
Of course, in your case, you will need to name your checkbox with an x:Name and use it like so:
<ColumnDefinition Width="150" Visibility="{Binding IsChecked,ElementName=chk,Converter={StaticResource b2v}}"/>
Just in case the other link is not available, here is the StaticResource:
<Window.Resources>
<BooleanToVisibilityConverter x:Key="b2v" />
</Window.Resources>