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

Gridview Column Header Style

5 Answers 614 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Joe Bohen
Top achievements
Rank 1
Joe Bohen asked on 12 Apr 2017, 12:02 PM

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

5 Answers, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 14 Apr 2017, 10:51 AM
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 you to write beautiful native mobile apps using a single shared C# codebase.
0
Joe Bohen
Top achievements
Rank 1
answered on 16 Apr 2017, 08:41 AM

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?

0
Stefan Nenchev
Telerik team
answered on 20 Apr 2017, 05:52 AM
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 you to write beautiful native mobile apps using a single shared C# codebase.
0
Joe Bohen
Top achievements
Rank 1
answered on 20 Apr 2017, 12:38 PM

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

0
Stefan Nenchev
Telerik team
answered on 25 Apr 2017, 10:12 AM
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 you to write beautiful native mobile apps using a single shared C# codebase.
Tags
PersistenceFramework
Asked by
Joe Bohen
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Joe Bohen
Top achievements
Rank 1
Share this question
or