Column Visibility from Binding

6 posts, 0 answers
  1. Rajesh
    Rajesh avatar
    13 posts
    Member since:
    Mar 2011

    Posted 16 Jun 2011 Link to this post

    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

  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 16 Jun 2011 Link to this post

    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
  3. Rajesh
    Rajesh avatar
    13 posts
    Member since:
    Mar 2011

    Posted 16 Jun 2011 Link to this post


    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


  4. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 16 Jun 2011 Link to this post

    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
  5. Justin
    Justin avatar
    4 posts
    Member since:
    Dec 2011

    Posted 23 Jan 2012 Link to this post

    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.

  6. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 24 Jan 2012 Link to this post

    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 >>

Back to Top