customizing default filters in Radgridview windows forms

1 Answer 72 Views
GridView
amit
Top achievements
Rank 1
amit asked on 20 Dec 2023, 10:40 AM | edited on 20 Dec 2023, 01:29 PM

Hi I am working on Radgridview where on a particular column I have hidden few options like below.

Private Sub grd_ContextMenuOpening(sender As Object, e As ContextMenuOpeningEventArgs) Handles grd.ContextMenuOpening
        Dim i As Integer = 0
        Dim IgnoreOperator() As String = {"Ends with", "Equals", "not equal to", "no filter"}
        If DirectCast(e.ContextMenuProvider, Telerik.WinControls.UI.GridCellElement).ColumnInfo.FieldName = "AcctNbr" Then
            While i < e.ContextMenu.Items.Count
                If Not IgnoreOperator.Contains(e.ContextMenu.Items(i).Text, StringComparer.CurrentCultureIgnoreCase) Then
                    e.ContextMenu.Items(i).Visibility = Telerik.WinControls.ElementVisibility.Collapsed
                End If
                i = i + 1
            End While
        End If
    End Sub

My requirement is to search data from a different a column of Dataview which is binded to the grid  however  column header is different.

I wrote below code expecting that  when `AcctNbr` is the header of column it will search the dataview(dv) based on the row filter and bind it the grid on UI but it's not working

Private Sub grd_FilterChanging(sender As Object, e As GridViewCollectionChangingEventArgs) Handles grd.FilterChanging
        dv.RowFilter =""
        If e.NewValue IsNot Nothing
        If DirectCast((DirectCast(e.NewItems, Object())(0)), Telerik.WinControls.Data.FilterDescriptor).[Operator] = Telerik.WinControls.Data.FilterOperator.IsEqualTo AndAlso DirectCast((DirectCast(e.NewItems, Object())(0)), Telerik.WinControls.Data.FilterDescriptor).PropertyName = "AcctNbr" Then
            Dim CurrentVal As String = CStr(e.NewValue)
            dv.RowFilter = "EnAcctNbr ='" & CurrentVal & "'"
        End If
        If DirectCast((DirectCast(e.NewItems, Object())(0)), Telerik.WinControls.Data.FilterDescriptor).[Operator] = Telerik.WinControls.Data.FilterOperator.IsNotEqualTo AndAlso DirectCast((DirectCast(e.NewItems, Object())(0)), Telerik.WinControls.Data.FilterDescriptor).PropertyName = "AcctNbr" Then
            Dim CurrentVal As String = CStr(e.NewValue)
            dv.RowFilter = "EnAcctNbr <>'" & CurrentVal & "'"
        End If
        End If

how can I achieve this behavior ? I tried to assign the updated dataview as datasource to the grid in `grd_CellEndEdit` event that too did not work. pls. help.

Regards,

Amit Rai

 

 

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 21 Dec 2023, 12:56 PM

Hello, Amit,

If I understand your requirement correctly you would like to type on a column header of the grid but filter a different column than the current one. 

The default filtering functionality that RadGridView offers, considers the column's FieldName property when creating the FilterDescriptors via the UI in the filtering row. If you need to introduce a different logic for the filtering behavior, the RadGridView control supports custom filtering where you can implement your logic and specify which column name to filter. Please refer to the following help article: Custom Filtering - WinForms GridView Control - Telerik UI for WinForms 

The CustomFiltering event in this situation allows you to control whether a row is visible or not according to the user's input. 

Our Demo application >> GridView >> Filtering >> Custom Filtering example is quite useful on this topic as well.

I hope this information helps. If you need any further assistance, please don't 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.

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