Change Background Color On Filter Column

1 Answer 6 Views
GridView
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
Martin Hamilton asked on 15 Jul 2025, 02:17 PM

On the gridview when a user enters a filter value, I would like for the background color of that filter to change to a different color (only for the column or columns where a filter has been entered) so that users can quickly see where they entered a filter value.

Currently, if the grid has many columns the user will enter a value (sometimes forget that they did that) and wonder why they have a filtered grid.  I know that sounds crazy but end users do that!  So, I'd like the Filter Cell Backcolor to be a different color so that it's Obvious that - that particular column has a filter applied to it.

Below, I show the code I'm using in the GridData_ViewCellFormatting event.  But the problem is - is that it changes the color for the entire filtering row (across all columns)... whereas I want the back color of the "Filter Cell" to change only for that particular column or columns where a filter has been applied.

It would be greatly appreciated is someone has the answer to solving this 'problem'.

Dim filterDescriptors = GridData.FilterDescriptors
If TypeOf e.CellElement Is Telerik.WinControls.UI.GridFilterCellElement Then
    DirectCast(e.CellElement.RowInfo, Telerik.WinControls.UI.GridViewFilteringRowInfo).Height = 28
    e.CellElement.DrawFill = True
    e.CellElement.NumberOfColors = 1
    e.CellElement.BackColor = Color.Beige
    e.CellElement.Font = New Font("Verdana", 10)
    For Each filterDescriptor In filterDescriptors
        Dim propertyName = filterDescriptor.PropertyName
        Dim filterOperator = filterDescriptor.Operator
        Dim expression = filterDescriptor.Expression
        Dim filterValue = filterDescriptor.Value
        If filterValue IsNot Nothing Then
            'If e.CellElement.Text = propertyName Then
            e.CellElement.BackColor = Color.LightGreen
            Exit Sub
            'End If
            'e.CellElement.BackColor = Color.Pink
        End If

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 15 Jul 2025, 06:32 PM

Hello, Martin,

You are on the right path, the correct approach to customize the filter cell color is by handling the GridData_ViewCellFormatting event. I edited your code snippet a little to reflect the behavior that you want to achieve. 

Please refer to the updated code snippet: 

Private Sub RadGridView1_ViewCellFormatting(sender As Object, e As CellFormattingEventArgs)
    If TypeOf e.CellElement Is GridFilterCellElement Then
        Dim filterDescriptors = RadGridView1.FilterDescriptors
        If TypeOf e.CellElement Is Telerik.WinControls.UI.GridFilterCellElement Then
            DirectCast(e.CellElement.RowInfo, Telerik.WinControls.UI.GridViewFilteringRowInfo).Height = 28
            e.CellElement.DrawFill = True
            e.CellElement.NumberOfColors = 1
            e.CellElement.BackColor = Color.Beige
            e.CellElement.Font = New Font("Verdana", 10)
            For Each filterDescriptor In filterDescriptors
                Dim propertyName = filterDescriptor.PropertyName
                Dim filterOperator = filterDescriptor.Operator
                Dim expression = filterDescriptor.Expression
                Dim filterValue = filterDescriptor.Value
                If filterValue IsNot Nothing AndAlso e.CellElement.ColumnInfo.Name Is propertyName Then
                    e.CellElement.BackColor = Color.LightGreen
                    Exit Sub
                End If
            Next
        End If
    End If
End Sub

Thus, only the cell that has a filter applied would be colored in LightGreen:

I hope this helps. If you have any other questions, do not hesitate to contact me.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 16 Jul 2025, 10:46 AM

Nadya,

This is PERFECT - THANK YOU!!

Tags
GridView
Asked by
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or