Hide gridviewdatacolumn when it is added in ColumnGroupDescriptor

7 posts, 0 answers
  1. Ankush
    Ankush avatar
    8 posts
    Member since:
    Oct 2012

    Posted 20 Oct 2012 Link to this post

    Hi,
    I am using a radgridview , in which i have few gridviewdatacolumn , i am adding a group descriptor for one of the column , and my requirement is, that column should be hidden from radgridview since i have grouped based on that, 
    further GridViewColumn.ShowColumnWhenGrouped Property is not available to me as i am using an older version of telerik Dll, is their any other way to solve this problem?

     following is the xaml of code for more clarity, so i want column Element Path to be hidden as it is used in group descriptor -

     <telerik:RadGridView.Columns>
                                                    <telerik:GridViewDataColumn  IsReadOnly="True"  IsGroupable="True"  Header="Element Path" DataMemberBinding="{Binding ElementPath}" Focusable="False" Width="Auto" TextAlignment="Left" IsEnabled="False"/>
                                                    <telerik:GridViewDataColumn  IsReadOnly="True"  IsGroupable="True"  Header="Category" DataMemberBinding="{Binding CategoryName}" Focusable="False" Width="Auto" TextAlignment="Left" IsEnabled="False" />
                                                    <telerik:GridViewDataColumn IsReadOnly="True"  IsGroupable="False"  Header="Name" DataMemberBinding="{Binding Name}" Width="Auto" Focusable="False" TextAlignment="Left" IsEnabled="False" />
                                                    <telerik:GridViewDataColumn IsReadOnly="True"  IsGroupable="False"  Header="Description" HeaderTextAlignment="Left" DataMemberBinding="{Binding Description}" Focusable="False" Width="200" TextAlignment="Left" IsEnabled="False" />
                                                    <telerik:GridViewDataColumn IsReadOnly="True"  IsGroupable="True"  Header="Type" DataMemberBinding="{Binding CannonicalType}" Focusable="False" TextAlignment="Left" Width="Auto" IsEnabled="False" />
                                                    <telerik:GridViewDataColumn  Header="Value"  IsGroupable="False"  Width="180"  DataMemberBinding="{Binding Value,Mode=TwoWay,ValidatesOnExceptions=True}"  CellTemplateSelector="{StaticResource CellTemplate}" CellEditTemplateSelector="{StaticResource EditTemplateSelector}"  SortingState="None" IsSortable="True"  TextAlignment="Left" IsEnabled="True">
                                                        <telerik:GridViewDataColumn.CellStyle>
                                                            <Style  BasedOn="{StaticResource {x:Type tt:GridViewCell}}" TargetType="tt:GridViewCell">
                                                                <Setter Property="FontWeight" Value="Normal" />
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding Path=IsDefaultValueModified,Mode= TwoWay}" Value="true">
                                                                        <Setter Property="FontWeight" Value="Bold" />
                                                                    </DataTrigger>
                                                                    <DataTrigger Binding="{Binding Path=ParameterInEditMode, Mode=TwoWay}"  Value="true">
                                                                        <Setter Property="FontStyle" Value="Italic" />
                                                                    </DataTrigger>
                                                                    <DataTrigger Binding="{Binding IsEnabled}" Value="true">
                                                                        <Setter Property="IsEnabled" Value="true" />
                                                                        <Setter Property="Focusable" Value="true" />
                                                                    </DataTrigger>
                                                                    <DataTrigger Binding="{Binding IsEnabled}" Value="false">
                                                                        <Setter Property="IsEnabled" Value="false" />
                                                                        <Setter Property="Focusable" Value="false" />
                                                                    </DataTrigger>
                                                                </Style.Triggers>
                                                            </Style>
                                                        </telerik:GridViewDataColumn.CellStyle>
     
                                                    </telerik:GridViewDataColumn>
                                                    <telerik:GridViewDataColumn  IsGroupable="False" IsReadOnly="True" Header="Resolved Value" DataMemberBinding="{Binding ResolvedValue}" TextAlignment="Left" Width="180" IsEnabled="False"/>
     
                                                </telerik:RadGridView.Columns>
                                                <telerik:RadGridView.GroupDescriptors>
                                                    <telerik:ColumnGroupDescriptor>
                                                        <telerik:ColumnGroupDescriptor.Column>
                                                            <telerik:GridViewColumn Header="Element Path"  GroupMemberPath="ElementPath" />
                                                        </telerik:ColumnGroupDescriptor.Column>
                                                    </telerik:ColumnGroupDescriptor>
                                                </telerik:RadGridView.GroupDescriptors>
    
    
    

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 23 Oct 2012 Link to this post

    Hello,

    You can set the grouped column be not visible once a Grouping event with GroupingEventAction.Place is raised. For example:

    private void clubsGrid_Grouping(object sender, GridViewGroupingEventArgs e)
          {
              if (e.Action == GroupingEventAction.Place)
              (e.GroupDescriptor as ColumnGroupDescriptor).Column.IsVisible = false;
          }

    Greetings,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Ankush
    Ankush avatar
    8 posts
    Member since:
    Oct 2012

    Posted 23 Oct 2012 Link to this post

    Hi,

    Using grouping event i can hide the visibility,  once i add( drag and drop the GridViewcolumn header ) or remove it from group panel , but since column group descriptor shows gridviewcolumn to be grouped as the window opens , i need a solution which hides the visibility of gridviewcolumn as the window opens. Is their any solution available for that.


    Thanks ,
    Ankush.
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 24 Oct 2012 Link to this post

    Hello,

     You could check the RadGridView.GroupDescriptors that are initially defined and based on the information from them hide the proper columns.

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Ankush
    Ankush avatar
    8 posts
    Member since:
    Oct 2012

    Posted 24 Oct 2012 Link to this post

    hi,
    Which event of radgrpoupDescriptor should i use so that i can get my desired result , if i am using Loaded event of radgridview and writing the following code in it , it is not hiding the corresponding column when window opens-

     private void rad1_Loaded(object sender, RoutedEventArgs e)
            {
                ColumnGroupDescriptor gd = rad1.GroupDescriptors[0] as ColumnGroupDescriptor;
                //ColumnGroupDescriptor gd1 = gd;
                gd.Column.IsVisible = false;
            }
      
    Thanks,
    Ankush.
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 25 Oct 2012 Link to this post

    Hi Ankush,

    I have tested this code and it works fine at my end. Please find attached my test project.

    Greetings,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  7. Ankush
    Ankush avatar
    8 posts
    Member since:
    Oct 2012

    Posted 25 Oct 2012 Link to this post

    hi didie,

    I am not sure why using the similar code , this approach is not working for me ,
    well any how i have fixed this by using following code-

        
     private void rad1_Loaded(object sender, RoutedEventArgs e)
            {
                //ColumnGroupDescriptor gd = rad1.GroupDescriptors[0] as ColumnGroupDescriptor;
                ////ColumnGroupDescriptor gd1 = gd;
                //gd.Column.IsVisible = false;
             ////   if (!isDefaultGroupingLoaded)
                {
                    //   isDefaultGroupingLoaded = true;
                    ColumnGroupDescriptor des = new ColumnGroupDescriptor();
                    des.Column = rad1.Columns["FirstName"as Telerik.Windows.Controls.GridViewColumn;
                    des.DisplayContent = "FirstName";
                    des.SortDirection = null;
                    rad1.GroupDescriptors.Add(des);
                    des.Column.IsVisible = false;
                }
            }

    thanks for your help.
Back to Top