I have a grid in which i wants to show some of the columns depending upon some business rules. So i set the Binding for the ISVISIBLE to an attribute of the view model but it is not able to hide the column.
Say i have view model EmployeeVM it has 2 attributes ( one is Observable Collection ( List of employees ) and other ISNAMEVISIBLE ) . This i binded to the Grid control. Set the item source to the Observable collection
Now i dont want Name column to visible for some scenarios so i set the ISNAMEVISIBLE to false. but still column is visible .
So i went to the Entity level ( Employee) and exposed one more property (NameVisible) and then this i binded to the column and this entity even implements INotifyPropertychnage but still no luck . column i still visible.
Can some suggest me why it is not invisible and the best way to achieve it ?
Regards,
Phani
5 Answers, 1 is accepted
Can you verify if your view-model implements INotifyPropertyChanged properly?
Regards,Vlad
the Telerik team
I did not implemented the INotifyPropertychanged in the viewmodel , but my entity do implement will that will not be suffice if i binded the entity property to the column, but that did not worked out .
Regards,
Phani
The DataContext for columns (and the grid itself) is your view-model - not the entities. Your entities will be set as DataContext for rows/cells.
Greetings,Vlad
the Telerik team
Here is some sample XAML:
<CheckBox x:Name="chk1" />
<CheckBox x:Name="chk2" />
<telerik:RadGridView CanUserFreezeColumns="False" ItemsSource="{Binding Resources}" AutoGenerateColumns="False" telerik:StyleManager.Theme="Windows7" EditTriggers="CellClick" >
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header="Col1" DataMemberBinding="{Binding Col1}" IsGroupable="False" IsFilterable="True" ShowDistinctFilters="False" IsVisible="{Binding ElementName=chk1, Path=IsChecked}" />
<telerik:GridViewDataColumn Header="Col2" DataMemberBinding="{Binding Col2}" IsGroupable="False" IsFilterable="True" ShowDistinctFilters="False" IsVisible="{Binding ElementName=chk2, Path=IsChecked}" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
In the above example, checking and unchecking chk1 will show and hide column 1 in the grid. Checking and unchecking chk2 does nothing.
Here is an example how to achieve your goal:
<Grid x:Name="LayoutRoot" Background="White"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition /> </Grid.RowDefinitions> <StackPanel> <CheckBox x:Name="chk1" IsChecked="{Binding Columns[\Col1\].IsVisible, ElementName=RadGridView1, Mode=TwoWay}" /> <CheckBox x:Name="chk2" IsChecked="{Binding Columns[\Col2\].IsVisible, ElementName=RadGridView1, Mode=TwoWay}"/> </StackPanel> <telerik:RadGridView x:Name="RadGridView1" CanUserFreezeColumns="False" ItemsSource="{Binding}" AutoGenerateColumns="False" telerik:StyleManager.Theme="Windows7" EditTriggers="CellClick" Grid.Row="1"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn Header="Col1" DataMemberBinding="{Binding Col1}" IsGroupable="False" UniqueName="Col1" IsFilterable="True" ShowDistinctFilters="False" /> <telerik:GridViewDataColumn Header="Col2" DataMemberBinding="{Binding Col2}" IsGroupable="False" UniqueName="Col2" IsFilterable="True" ShowDistinctFilters="False" /> </telerik:RadGridView.Columns> </telerik:RadGridView> </Grid>Vlad
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
