Gridview Column Header Style

6 posts, 0 answers
  1. Joe Bohen
    Joe Bohen avatar
    67 posts
    Member since:
    May 2009

    Posted 12 Apr Link to this post

    I am using a style to color gridview column headers when a filter is applied to the gridview or when it is removed to change the color back to the default.  I save filters etc. using the persistence manager.  When I reload the gridview settings via the persistence manager the Filtered event does not fire. Is there a method that would replicate the adding of the filter or am I able to iterate the columns collection to identify the filtered columns?

     

    Regards,

    Joe

  2. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    501 posts

    Posted 14 Apr Link to this post

    Hi Joe,

    The Filtered event would not fire when you programmatically add filter descriptors to the RadGridView's FilterDescriptors collection. It would only fire if you apply the filtering through the UI.

    In order to get the filter descriptors, you can iterate over the columns collection of the RadgridView and check whether the ColumnFilterDescriptor is active:

    //where clubsGrid is the RadGridView instance
    foreach (var column in clubsGrid.Columns)
     {
         var cfd = (column as GridViewDataColumn).ColumnFilterDescriptor;
         if (cfd.IsActive)
         {
            // MessageBox.Show((column as GridViewDataColumn).Header.ToString());
         }
     }
    Would this work for you?

    Regards,
    Stefan Nenchev
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Joe Bohen
    Joe Bohen avatar
    67 posts
    Member since:
    May 2009

    Posted 16 Apr in reply to Stefan Nenchev Link to this post

    Hi Stefan,

    Thanks for your reply that is exactly what I wanted! I have another issue, when I reset the style by 

    column.HeaderCellStyle = TryCast(Me.Resources("clearStyle"), Style)

    <Style x:Key="clearStyle" TargetType="telerik:GridViewHeaderCell"/>

    The header style dose not return to the gridviews theme which is set in the xaml as 

    <telerik:StyleManager.Theme>
                                                <telerik:Office_SilverTheme/>
                                            </telerik:StyleManager.Theme>
                                            <telerik:RadGridView.RowStyle>
                                                <Style TargetType="telerik:GridViewRow">
                                                    <Setter Property="Background" Value="{Binding Status,Converter={StaticResource BackGroundConverter},ConverterParameter=Binding Status}"></Setter>
                                                </Style>
                                            </telerik:RadGridView.RowStyle>

     

    The gridview header cell is black! Please see the image,  can you help with this thanks?

  4. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    501 posts

    Posted 20 Apr Link to this post

    Hi Joe,

     Instead of referencing the already created style, you can try assigning a new one to the HeaderCellStyle with the same properties set. In this case, you should create the style in the code behind similar to the discussion in the following thread - Creating a style in code behind. Add respective setters and then set this newly created style to the HeaderCellStyle of the particular column. Please give it a try and update the thread.

    Regards,
    Stefan Nenchev
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  5. Joe Bohen
    Joe Bohen avatar
    67 posts
    Member since:
    May 2009

    Posted 20 Apr in reply to Stefan Nenchev Link to this post

    Hi Stefan,

    Thanks for your advice I have followed your advice and created a new style which is very close to the Office Silver theme apart from the border which in the true style is transparent but in my style is black! The header and row are very slightly miss aligned. This would do but it would have been nice to get the style exactly the same. the code is below and I have added an image of before and after the style has been applied.

    Regards,

    Joe

     Private gridstyle As New Style(GetType(GridViewHeaderCell)) ' declared at class level

    In the New() sub

     Dim black As New SolidColorBrush
                black.Color = Colors.Black
                Dim thickness As New Thickness
                thickness.Top = 0.5
                thickness.Bottom = 0.5
                thickness.Left = 0.5
                thickness.Right =0.5
                Dim col1 As Color = DirectCast(ColorConverter.ConvertFromString("#FFE1E1EA"), Color)
                Dim bordercolor As Color = DirectCast(ColorConverter.ConvertFromString("#FF777792"), Color)
                Dim borderbrush As New SolidColorBrush
                borderbrush.Color = colors.transparent
                Dim myLinearGradientBrush As New LinearGradientBrush()
                myLinearGradientBrush.StartPoint = New Point(0, 0)
                myLinearGradientBrush.EndPoint = New Point(1, 1)
                myLinearGradientBrush.GradientStops.Add(New GradientStop(col1, 1.0))
                'Dim style As New Style(GetType(GridViewHeaderCell))
                gridstyle.Setters.Add(New Setter(Control.BorderThicknessProperty, thickness))
                gridstyle.Setters.Add(New Setter(Control.BackgroundProperty, myLinearGradientBrush))
                gridstyle.Setters.Add(New Setter(GridViewHeaderCell.ForegroundProperty, black))
                gridstyle.Setters.Add(New Setter(GridViewHeaderCell.BorderBrushProperty, borderbrush))
                Resources.Add(GetType(GridViewHeaderCell), gridstyle)

    in the grids filtered event

    Private Sub jobsgrid_Filtered(sender As Object, e As GridViewFilteredEventArgs) Handles jobsgrid.Filtered
            Try

           
                For Each descriptor As FilterDescriptor In e.Added
                    Dim column As GridViewColumn = Me.jobsgrid.Columns(descriptor.Member)
                    Dim colour As New SolidColorBrush
                    'column.Background = New SolidColorBrush(Colors.Green)
                    column.HeaderCellStyle = TryCast(Me.Resources("style1"), Style)
                Next
                For Each descriptor As FilterDescriptor In e.Removed
                    Dim column As GridViewColumn = jobsgrid.Columns(descriptor.Member)
                    column.HeaderCellStyle = gridstyle
                Next
             
            Catch ex As Exception
            Finally
            End Try
        End Sub

  6. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    501 posts

    Posted 25 Apr Link to this post

    Hello Joe,

    Would it be possible to raise a support ticket and provide a sample of your application that shows the behavior so we can investigate your exact scenario? It seems that there is something small missing so it will be great if we can have a look at your exact implementation.

    Regards,
    Stefan Nenchev
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top