Results 1 to 2 of 2

Thread: Troubles with Raising Events

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    3

    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!

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Troubles with Raising Events

    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
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width