Reputation: 13313
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.
Upvotes: 3
Views: 464
Reputation: 5358
Since lambdas cause a problem you could try implementing them manually using an object:
Class FooCurry
Private bar as Foo
Private Sub new (foo as Foo)
bar = foo
End Sub
Public sub DoFoo()
bar.SetFoo()
EndSub
End Class
dim foocurry as new FooCurry(foo)
BeginInvoke(New MethodInvoker(AdressOf foocurry.DoFoo))
This is how lambdas are implemented under the hood, so this should work. You could generalise the object to take a delegate and use it in more places.
Upvotes: 2
Reputation: 564811
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)
Upvotes: 3