We help IT Professionals succeed at work.
Get Started

VB.NET Event not Being Handled

359 Views
Last Modified: 2013-11-26
Hello Experts,

I am just dipping into custom events and have hit a major snag. An event raised in one class is not being handled when another class initiates the sub that contains the event. I have attached my code. All help is greatly appreciated.
Public Class ResultCollection
        Inherits CollectionBase
        Public Event ResultLoaded(ByVal CurrentRecord As Integer, ByVal TotalRecords As Integer)
        Default Public Overridable ReadOnly Property Item(ByVal index As Integer) As Result
            Get
                Return CType(Me.List(index), Result)
            End Get
        End Property

        Public Sub Add(ByVal Result As Result)
            List.Add(Result)
        End Sub
        Public Sub New()

        End Sub
        Public Sub New(ByVal CycleCountCompletionID As Integer)
            Dim CurrCount As Integer = 0
            Dim TotalRecords As Integer = 0

            Dim SQL As String = [OMITTED]
            Dim DS As DataSet = VSMS.GetDataSet(SQL, VSMS.TRIPConnStr)
            TotalRecords = DS.Tables(0).Rows.Count

            For Each DR As DataRow In DS.Tables(0).Rows
                CurrCount += 1
                Me.Add(New Result(Convert.ToInt32(DR.Item("CycleCountResultID"))))
                RaiseEvent ResultLoaded(CurrCount, TotalRecords) '<-- EVENT FIRES HERE AND IS HANDLED PROPERLY IF I ADD AN EVENT HANDLER TO THE SAME CLASS
            Next

        End Sub



    End Class

Public Class Completion
        Private WithEvents _Results As New ResultCollection

        Public Sub LoadResults()

            _Results = New ResultCollection(CycleCountCompletionID) '<--This SHOULD get the event handler to start firing events.

        End Sub
        
Public Sub _Results_ResultLoaded(ByVal CurrentRecord As Integer, ByVal TotalRecords As Integer) Handles _Results.ResultLoaded
'EVENT SHOULD BE RAISED HERE, BUT DEBUGGING SHOWS THAT IT IS NOT HITTING THIS SUB.
            Dim X As String = ""
        End Sub
End Class

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 2 Answers and 5 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE