Question Dynamic AddressOf

scottsanpedro

Member
Joined
Jan 24, 2009
Messages
21
Programming Experience
1-3
Hi All, I hope someone can help me.
I have some code and just need the calling AddressOf to be dynamic
VB.NET:
  If view IsNot Nothing Then
            Dim filterer = New FiltersAdminvb(text.SelectedItem.ToString)
            view.Filter = New Predicate(Of Object)(AddressOf filterer.FilterSite)
        End If
filterer.FilterSite is the code that I need to replace each time with another method call.
Thanks for any help. Scott
 
Can you clarify /explain more ? At some point in your code this method must explicitly determined right?
 
Yes. It's actually a WPF application but its more a code problem than anything else.

I have a filter set on a datagrid which uses the code I placed on the original post. Each filter I use, the only code that changes on my procedure is the AddressOf address.

I have code in a separate class called FiltersAdminvb. Here is two examples of receiving code;

VB.NET:
Public Function FilterEngineerName(ByVal item As Object) As Boolean
        Dim viewList As View_AdminList = CType(item, View_AdminList)

        If viewList IsNot Nothing Then
            If viewList.RS_EngineerName = SearchData Then
                Return True
            End If
        End If
        Return False

    End Function

    Public Function FilterSite(ByVal item As Object) As Boolean
        Dim viewList As View_AdminList = CType(item, View_AdminList)

        If viewList IsNot Nothing Then
            If viewList.Call_Site_Name = SearchData Then
                Return True
            End If
        End If
        Return False

    End Function

Does that make more sense?? Thanks Scott
 
VB.NET:
If x = y Then
    view.Filter = AddressOf FilterA
Else
    view.Filter = AddressOf FilterB
End If
Does that help?
 
sorry. A case of pointing out the obvious. Been a long day. Ignore me! and thanks for your time

VB.NET:
If view IsNot Nothing Then
            Dim filterer = New FiltersAdminvb(text.SelectedItem.ToString)
            If filterCall = "Site" Then
                view.Filter = New Predicate(Of Object)(AddressOf filterer.FilterSite)
            ElseIf filterCall = "Engineer" Then
                view.Filter = New Predicate(Of Object)(AddressOf filterer.FilterEngineerName)
            End If
        End If
 
Back
Top