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

filter on multiple columns

1 Answer 282 Views
GridView
This is a migrated thread and some comments may be shown as answers.
nhalm
Top achievements
Rank 1
nhalm asked on 23 Sep 2011, 09:33 PM
I know that there are many forum posts regarding filtering but I am having the hardest time trying to figure out how to accomplish this filter scenario:

I have 4 columns, Rdel, RAdd, RMod, RErr.
right now I have those columns set as Integer type in my datatable that I bind to the radgridview.  I handle changhing the values as need be but I need to be able to use filters so that I can not rows.  The way I have been trying to set the filters up I have used a custom context menu that uses a check type menuitem.  So when that value changes I am trying to add or remove descriptors.  So I may have many or no filters applied to the grid.  Right now I have something like this and it sort of works but I just wanted to kbnow if there is a better way of doing this.

  Public Const conMODIFIED As String = "RMod"
    Public Const conADDED As String = "RAdd"
    Public Const conDELETED As String = "RDel"
    Public Const conERRORROW As String = "RErr"
    Public Const conCHANGESLINK As String = "RCHGS"
    Public Const conROWID As String = "iRowID"
    Public Const conLSGRDTYPE As String = "lsGrdDataType"
    Public Const conCHFLAG As Integer = 1 '"x"
    Public Const conUCHFLAG As Integer = 0 '""

Public Sub ViewRowStates(Optional ByVal UnchangedRows As Boolean = True, Optional ByVal ChangedRows As Boolean = True, _
                         Optional ByVal AddedRows As Boolean = True, Optional ByVal DeletedRows As Boolean = True, _
                         Optional ByVal ErrorRows As Boolean = False)
 
    Me.FilterDescriptors.Remove(conADDED)
    Me.FilterDescriptors.Remove(conMODIFIED)
    Me.FilterDescriptors.Remove(conDELETED)
    Me.FilterDescriptors.Remove(conERRORROW)
    Dim cFilter As New Telerik.WinControls.Data.CompositeFilterDescriptor
    If Not UnchangedRows Then
        Dim compFilter As New Telerik.WinControls.Data.FilterDescriptor
        compFilter.PropertyName = conMODIFIED
        compFilter.Operator = Telerik.WinControls.Data.FilterOperator.IsEqualTo
        compFilter.Value = conCHFLAG
        compFilter.IsFilterEditor = True
        cFilter.FilterDescriptors.Add(compFilter)
    End If
    If Not ChangedRows Then
        Dim compFilter As New Telerik.WinControls.Data.FilterDescriptor
        compFilter.PropertyName = conMODIFIED
        compFilter.Operator = Telerik.WinControls.Data.FilterOperator.IsNotEqualTo
        compFilter.Value = conCHFLAG
        compFilter.IsFilterEditor = True
 
        cFilter.FilterDescriptors.Add(compFilter)
    End If
    If Not AddedRows Then
        Dim compFilter As New Telerik.WinControls.Data.FilterDescriptor
        compFilter.PropertyName = conADDED
        compFilter.Operator = Telerik.WinControls.Data.FilterOperator.IsNotEqualTo
        compFilter.Value = conCHFLAG
        compFilter.IsFilterEditor = True
 
        cFilter.FilterDescriptors.Add(compFilter)
    End If
    If Not DeletedRows Then
        Dim compFilter As New Telerik.WinControls.Data.FilterDescriptor
        compFilter.PropertyName = conDELETED
        compFilter.Operator = Telerik.WinControls.Data.FilterOperator.IsNotEqualTo
        compFilter.Value = conCHFLAG
        compFilter.IsFilterEditor = True
 
        cFilter.FilterDescriptors.Add(compFilter)
    End If
    If Not ErrorRows Then
        Dim compFilter As New Telerik.WinControls.Data.FilterDescriptor
        compFilter.PropertyName = conERRORROW
        compFilter.Operator = Telerik.WinControls.Data.FilterOperator.IsNotEqualTo
        compFilter.Value = conCHFLAG
        compFilter.IsFilterEditor = True
 
        cFilter.FilterDescriptors.Add(compFilter)
    End If
 
    Me.FilterDescriptors.Add(cFilter)
End Sub


If there is a better way to handle this scenario I would appreciate any suggestions.   The main thing is that I will add and remove filters on a single column and not want to lose the existing ones.  I would also need to be able to only see the rows that have a 1 in any of those columns.  A row could have a 1 in conAdded, conModified, and conDeleted.  That is so I can undo a single operation, such as a delete and still know that row was added.

Thanks once again.

Nick

1 Answer, 1 is accepted

Sort by
0
Accepted
Alexander
Telerik team
answered on 28 Sep 2011, 10:56 AM
Hello Nhalm,

Thank you for your question.

The CompositeFilterDescriptor is a nice approach to accomplish your scenario for defining filters for your columns. Please let us know if you meet difficulties implementing your solution further.

Best regards,
Alexander
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
nhalm
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or