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 SelectBest Regards,
V. Adler
8 Answers, 1 is accepted
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 IfEnd SubDetailed 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
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.UIImports Telerik.WinControlsPublic 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 SubEnd ClassI 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
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 IfEnd SubI hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
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" Then03. If e.CellElement.ColumnInfo.Index = 0 Then04. Dim cell As GridHeaderCellElement = TryCast(e.CellElement, GridHeaderCellElement)05. If cell IsNot Nothing Then06. cell.FilterButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed07. End If08. End If09.End SubTake 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.ViewCellFormatting02. 'If e.CellElement.ColumnInfo.HeaderText = "Id" Then03. If e.CellElement.ColumnInfo.Index = 0 Then04. Dim cell As GridHeaderCellElement = TryCast(e.CellElement, GridHeaderCellElement)05. If cell IsNot Nothing Then06. cell.FilterButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed07. End If08. End If09.End SubFinally, this works perfectly.
Thanks for your time, best regards,
V. Adler
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_ViewCellFormattingEnd SubI hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
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
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
Thank you Hristo, this is just what I needed!
~Elliott
