Show/Hide Columns Question

4 posts, 0 answers
  1. toddhd
    toddhd avatar
    21 posts
    Member since:
    Aug 2006

    Posted 02 Mar 2011 Link to this post

    I am trying to show/hide columns in the GridView by Binding checkboxes to it, just like this example:

    http://www.telerik.com/help/silverlight/radgridview-how-to-show-hide-columns-outside-of-the-radgridview.html

    However, it is failing in my project. Is there some setting I'm adding/missing that is breaking this? The following actually throws an error and the designer won't render...

            <StackPanel x:Name="CustomizeGrid" Background="Transparent" Orientation="Horizontal">
                <ListBox ItemsSource="{Binding Columns, ElementName=WorklistGridView}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <CheckBox Content="{Binding Header}" IsChecked="{Binding IsVisible, Mode=TwoWay}" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                <telerik:RadGridView x:Name="WorklistGridView" AutoGenerateColumns="False" RowIndicatorVisibility="Collapsed" IsReadOnly="True" SelectionMode="Multiple" 
                                 CanUserSelect="False" IsSynchronizedWithCurrentItem="False" ItemsSource="{Binding Mode=OneWay}" IsFilteringAllowed="True">
                    <telerik:RadGridView.Columns>
                        <telerik:GridViewSelectColumn x:Name="Select" IsResizable="False" />
                        <telerik:GridViewDataColumn Header="Status" DataMemberBinding="{Binding OrderStatusDescription}"/>
                        <telerik:GridViewDataColumn Header="Patient Name" DataMemberBinding="{Binding PatientName}"/>


    If I change this:
    <CheckBox Content="{Binding Header}"

    TO this:
    <CheckBox Content="{Binding WorklistGridView.Header}"

    Then it will render the checkboxes, but there is no text beside them?
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 08 Mar 2011 Link to this post

    Hi toddhd,

    I have tested your XAMl. It seems the problem was in the select column missing a header. Then when trying to bind it in the listbox , the null value  caused an exception. (added an empty header for the select column).

    Here is a fixed version of the XAML (tested and working).
    <StackPanel x:Name="CustomizeGrid" Background="Transparent" Orientation="Horizontal">
        <ListBox ItemsSource="{Binding Columns, ElementName=WorklistGridView}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <CheckBox  Content="{Binding Header}" IsChecked="{Binding IsVisible, Mode=TwoWay}" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <telerik:RadGridView x:Name="WorklistGridView" AutoGenerateColumns="False" RowIndicatorVisibility="Collapsed" IsReadOnly="True" SelectionMode="Multiple" 
                         CanUserSelect="False" IsSynchronizedWithCurrentItem="False" ItemsSource="{Binding Mode=OneWay}" IsFilteringAllowed="True">
            <telerik:RadGridView.Columns>
                <telerik:GridViewSelectColumn Header=""  x:Name="Select" IsResizable="False" />
                <telerik:GridViewDataColumn Header="Status" DataMemberBinding="{Binding OrderStatusDescription}"/>
                <telerik:GridViewDataColumn Header="Patient Name" DataMemberBinding="{Binding PatientName}"/>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </StackPanel>


    All the best,
    Pavel Pavlov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. DevCraft banner
  4. Lauren
    Lauren avatar
    37 posts
    Member since:
    Jan 2010

    Posted 02 Jun 2011 Link to this post

    Hi,

    How would you remove the Select Column from the listbox ?
    For now i'm also binding the IsEnabled property of the checkbox to the IsREorderable property of the column so that the user cannot remove that column (assuming that's the only column which is not reorderable...). Is there a better way ?

    I was also wondering how could i handle an additional checkbox to "Select All" ? or how to bind the checked status of a "Select All" checkbox to the listbox ones ?
    and same with "Unselect All" ?
    I'm trying to retrieve the checkboxes from the listbox and change their checked status accordingly but i'm having trouble actually retrieving those checkboxes.

    Thank you for your help.
    Laurence
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 06 Jun 2011 Link to this post

    Hi Lauren,

    Regarding your first question  - you should use a converter in the binding for the ItemsSource for the ListBox.
    ItemsSource="{Binding Columns, ElementName=WorklistGridView}"

    shouold look like :

    ItemsSource="{Binding Columns, ElementName=WorklistGridView, Converter={StaticResource MyConverter}"

    where My converter is a custom implemented IValueConverter. In teh convert method you sould filter the items ( columns) , so that you see only those needed.

    Regarding your second question :
    I would always recommend to not traverse visual elements when there is another way , so instead of taking the checkboxes ,
    you can foreach the columns.
    E.g. in the Checked event of the "Select all" checkbox, you can foreach the columns and set their IsVisible property.  Since we have two way binding , checkboxes in the listbox will automatically update .

    If all this sounds obscure - let me know , and I will try to gather  a small sample for you.

    All the best,
    Pavel Pavlov
    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
Back to Top