Troubles with Raising Events
Hi
I have a class with a event
Code:
Public Class MyClass
Public Event MyEvent(ByVal Argument As String)
Private Sub Whatever()
RaiseEvent MyEvent("My Argument")
end sub
End Class
This works fine if i have only one instance of that class.
The problem is that when i have more than one instance of this class like this:
Code:
Private Sub IwDataGrid1_CellDoubleClick(ByVal Argument As String) Handles MyClassInstance1.MyEvent
MsgBox(Argument )
End Sub
Private Sub IwDataGrid2_CellDoubleClick(ByVal Argument As String) Handles MyClassInstance2.MyEvent
MsgBox(Argument )
End Sub
the .NET frameworks triggers a "System.NullReferenceException"
I would be gratefull if someone could explain me why this happens and how can i solve this problem!
Re: Troubles with Raising Events
Quote:
Originally posted by xondokan
Hi
I have a class with a event
Code:
Public Class MyClass
Public Event MyEvent(ByVal Argument As String)
Private Sub Whatever()
RaiseEvent MyEvent("My Argument")
end sub
End Class
This works fine if i have only one instance of that class.
The problem is that when i have more than one instance of this class like this:
Code:
Private Sub IwDataGrid1_CellDoubleClick(ByVal Argument As String) Handles MyClassInstance1.MyEvent
MsgBox(Argument )
End Sub
Private Sub IwDataGrid2_CellDoubleClick(ByVal Argument As String) Handles MyClassInstance2.MyEvent
MsgBox(Argument )
End Sub
the .NET frameworks triggers a "System.NullReferenceException"
I would be gratefull if someone could explain me why this happens and how can i solve this problem!
I dont think there is anything wrong with the events. The messagebox class doesnt raise an error even if you pass "Nothing" to it. Possibly MyClassInstance1 or MyClassInstance2 arent decalred properly?
you know you can add event handlers like this also:
AddHandler MyClassInstance1.MyEvent, Addressof IwDataGrid1_CellDoubleClick
try that and see what happens