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

Column Visibility from Binding

5 Answers 229 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rajesh
Top achievements
Rank 1
Rajesh asked on 16 Jun 2011, 03:58 PM
Hello All , 

 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

Sort by
0
Vlad
Telerik team
answered on 16 Jun 2011, 05:13 PM
Hi,

 Can you verify if your view-model implements INotifyPropertyChanged properly? 

Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rajesh
Top achievements
Rank 1
answered on 16 Jun 2011, 05:31 PM

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


0
Vlad
Telerik team
answered on 16 Jun 2011, 05:33 PM
Hello,

 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Justin
Top achievements
Rank 1
answered on 23 Jan 2012, 11:03 PM
I am also experiencing this problem with the Q3 2011 version.  I am binding the isVisibility property to the isChecked property of a check box elsewhere on the form.  The first column of the grid behaves as expected, but the others do not update the property.

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.

0
Vlad
Telerik team
answered on 24 Jan 2012, 10:24 AM
Hi,

 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>

All the best,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Rajesh
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Rajesh
Top achievements
Rank 1
Justin
Top achievements
Rank 1
Share this question
or