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

Excel like filtering - hide filtering symbol in column header

8 Answers 97 Views
GridView
This is a migrated thread and some comments may be shown as answers.
V
Top achievements
Rank 1
V asked on 23 Feb 2016, 10:29 AM

Hello, 

is it possible to hide the filter symbol in a specific column header while excel-like filtering remains enabled? 

I have to filter a specific column via some radio buttons only.

This works for me: 

Private Sub rbAktiv_CheckedChanged(sender As Object, e As EventArgs) Handles rbAktivAuftraege.CheckedChanged
 
        Dim filter As New FilterDescriptor()
        Dim filtervalue As String = String.Empty
        filter.PropertyName = "oa_status"
        filter.[Operator] = FilterOperator.Contains
        filter.IsFilterEditor = True
        Select Case True
            Case sender Is rbAktivAuftraege
                Me.RGV_auftraege.FilterDescriptors.Clear()
                filtervalue = CStr("aktiv")
                filter.Value = filtervalue
                Me.RGV_auftraege.FilterDescriptors.Add(filter)
End Select

Best Regards,

V. Adler

 

 

 

8 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 23 Feb 2016, 03:57 PM
Hello V,

Thank you for writing.

If I understand you correctly, you would like to have an excel-like filtering in your RadGridView  and at the same time hide the filter button for some columns, so that they cannot be filtered. This can be easily accomplished by using the ViewCellFormatting event: 
Private Sub radGridView1_ViewCellFormatting(sender As Object, e As CellFormattingEventArgs)
    If e.CellElement.ColumnInfo.Name = "Age" Then
        Dim cell As GridHeaderCellElement = TryCast(e.CellElement, GridHeaderCellElement)
        If cell IsNot Nothing Then
            cell.FilterButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed
        End If
    End If
End Sub

Detailed information on how cells can be formatted is available here: Formatting Cells.

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
V
Top achievements
Rank 1
answered on 23 Feb 2016, 05:07 PM

Hello, 

thank you for your answer. 

Unfortunately your code is not working. I made a small and simple demo project with a mysql database and a dataset with project designer. The table in the database has two columns named oakundeID and oa_kunde_name. I tried to hide the cellfilter button in oa_kunde_name but failed.

This is my code: 

Imports Telerik.WinControls.UI
Imports Telerik.WinControls
 
Public Class Form1
 
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
                 Me.Oa_kundeTableAdapter.Fill(Me.OaDataSet.oa_kunde)
    End Sub
    Private Sub radGridView1_ViewCellFormatting(sender As Object, e As CellFormattingEventArgs)
        If e.CellElement.ColumnInfo.Name = "oa_kunde_name" Then
            Dim cell As GridHeaderCellElement = TryCast(e.CellElement, GridHeaderCellElement)
            If cell IsNot Nothing Then
                cell.FilterButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed
            End If
        End If
    End Sub
End Class

I attached a screenshot where you can see that the cellfilterbutton is still visible. 

Additional informaition I forgot in my initial posting: I am using 2015.2.728, not 2016.1.216. 

Thanks for your help. 

Best regards,

V. Adler

0
Hristo
Telerik team
answered on 25 Feb 2016, 02:39 PM
Hello,

Thank you for writing back.

I also tested the solution with the 2015.2.728 version of the assemblies and on my end it is working. Please make sure that indeed the name of your column is the one you validate in the ViewCellFormating event. If you like you can also perform the check by index or the value of the HeaderText property. Please check my code snippet below: 
Private Sub RadGridView1_ViewCellFormatting(sender As Object, e As Telerik.WinControls.UI.CellFormattingEventArgs)
    'If e.CellElement.ColumnInfo.HeaderText = "Id" Then
    If e.CellElement.ColumnInfo.Index = 0 Then
        Dim cell As GridHeaderCellElement = TryCast(e.CellElement, GridHeaderCellElement)
        If cell IsNot Nothing Then
            cell.FilterButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed
        End If
    End If
End Sub

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
V
Top achievements
Rank 1
answered on 25 Feb 2016, 05:43 PM

Hello, thanks for your answer.

Your code snippet still does not work. Because there is a litte mistake. This is your code:

01.Private Sub RadGridView1_ViewCellFormatting(sender As Object, e As Telerik.WinControls.UI.CellFormattingEventArgs)
02.    'If e.CellElement.ColumnInfo.HeaderText = "Id" Then
03.    If e.CellElement.ColumnInfo.Index = 0 Then
04.        Dim cell As GridHeaderCellElement = TryCast(e.CellElement, GridHeaderCellElement)
05.        If cell IsNot Nothing Then
06.            cell.FilterButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed
07.        End If
08.    End If
09.End Sub

Take a look a line 01: there is no handle clause. So I changed your code to: 

01.Private Sub RadGridView1_ViewCellFormatting(sender As Object, e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.ViewCellFormatting
02.    'If e.CellElement.ColumnInfo.HeaderText = "Id" Then
03.    If e.CellElement.ColumnInfo.Index = 0 Then
04.        Dim cell As GridHeaderCellElement = TryCast(e.CellElement, GridHeaderCellElement)
05.        If cell IsNot Nothing Then
06.            cell.FilterButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed
07.        End If
08.    End If
09.End Sub

Finally, this works perfectly. 

Thanks for your time, best regards, 

V. Adler

 

0
Hristo
Telerik team
answered on 26 Feb 2016, 03:30 PM
Hi,

Thank you for writing. 

I am glad that you resolved the issue. Actually, the code snippet I sent you is correct, it only misses the subscription to the event which can be performed in the form`s constructor for example:
Sub New()
 
    InitializeComponent()
 
    AddHandler Me.RadGridView1.ViewCellFormatting, AddressOf RadGridView1_ViewCellFormatting
End Sub

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
V
Top achievements
Rank 1
answered on 26 Feb 2016, 05:48 PM

Hello, 

your code snippet is correct, of course.

I usually subscribe the events via the dropdown menu in the designer so I did not check what you have done.. 

I apologize for my affront. 

Best regards, 

V. Adler

 

0
Hristo
Telerik team
answered on 29 Feb 2016, 10:40 AM
Hello V,

Indeed, in one can attach event handlers using both approaches. The important thing is that you have accomplished your task.

Please let me know if I can assist you any further.

Regards,
Hristo Merdjanov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Elliott
Top achievements
Rank 2
answered on 14 Nov 2017, 08:23 PM

Thank you Hristo, this is just what I needed!

~Elliott

Tags
GridView
Asked by
V
Top achievements
Rank 1
Answers by
Hristo
Telerik team
V
Top achievements
Rank 1
Elliott
Top achievements
Rank 2
Share this question
or