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

Code Share: Hide Filter row text

1 Answer 72 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jason Parrish
Top achievements
Rank 1
Jason Parrish asked on 14 Mar 2011, 10:46 PM
If you don't like the way the RadGridView adds the Filter text (e.g. Contains, Equals, etc) in the Filter row, you can use this code that I wrote.  The text is unreadable in skinnier columns.  Plus, it confused my users since clicking on the word "Contains" did not automatically allow them to start typing; they had to click next to the word.

Anyways, this code simply collapses the text element and adds a tooltip to the filter row's cell and button.
Private Sub RadGridView1_ToolTipTextNeeded(ByVal sender As Object, ByVal e As Telerik.WinControls.ToolTipTextNeededEventArgs) Handles RadGridView1.ToolTipTextNeeded
    If TryCast(sender, GridFilterCellElement) IsNot Nothing Then
        e.ToolTipText = CType(sender, GridCellElement).ToolTipText
    End If
End Sub
 
Private Sub RadGridView1_ViewCellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.ViewCellFormatting
    HideFilterText(e.CellElement)
End Sub
 
 
Friend Sub HideFilterText(ByVal CellElement As GridCellElement)
    Dim oFilterCellElement As GridFilterCellElement
    Try
        If TryCast(CellElement, GridFilterCellElement) IsNot Nothing Then
            oFilterCellElement = CType(CellElement, GridFilterCellElement)
            oFilterCellElement.ToolTipText = oFilterCellElement.FilterOperatorText.Text.Replace(":", "")
            oFilterCellElement.FilterButton.ToolTipText = oFilterCellElement.FilterOperatorText.Text.Replace(":", "")
            oFilterCellElement.FilterOperatorText.Visibility = Telerik.WinControls.ElementVisibility.Collapsed
        End If
    Catch ex As Exception
        ' Do nothing
    End Try
 
End Sub


I now use this on all my grids within my current project.  It would be nice if something similar was built in.  If it is already, then I've missed it in the documentation.

Feel free to offer code improvements or another way.

1 Answer, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 15 Mar 2011, 12:01 PM
Hello Jason,

Good work on this one, but the tooltip text will just reflect the default selection, if the user changes the filter operator, that change will not be applied to the tooltip.

Keep up the good work

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
Tags
GridView
Asked by
Jason Parrish
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Share this question
or