vb.net.net-2.0begininvoke

AdressOf method signature


Since I can't put in parameters, how can I respect the following signature?

Private Sub SetFocusToRow(ByRef ultraGridRow As Infragistics.Win.UltraWinGrid.UltraGridRow)
    grdSoldeOuverture.ActiveCell = ultraGridRow.Cells(0)
    grdSoldeOuverture.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode)
End Sub

When I call it like this

Me.BeginInvoke(New MethodInvoker(AddressOf Me.SetFocusToTemplateAddRow))

I'm on .NET 2.0 in Visual Studio 2005 with Microsoft Visual Basic 2005 so a lambda expression is not an option.


Solution

  • You can use a lambda to capture the requirements and pass them in:

    Foo arg = GetTheFoo()
    
    BeginInvoke(New MethodInvoker(Sub() SetFoo(arg)))
    

    Edit:

    First, change your method to not pass ByRef - this is unnecessary:

    Private Sub SetFocusToRow(ByVal ultraGridRow As Infragistics.Win.UltraWinGrid.UltraGridRow)
        grdSoldeOuverture.ActiveCell = ultraGridRow.Cells(0)
        grdSoldeOuverture.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode)
    End Sub
    

    Next, define a delegate:

    ' Define your delegate:
    Delegate Sub SetFocusToRowDelegate(ByVal ultraGridRow As Infragistics.Win.UltraWinGrid.UltraGridRow)
    

    Then you can call via:

    BeginInvoke(new SetFocusToRowDelegate(AddressOf SetFocusToRow), arg)