|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Handling Events in VB.NetI have a project called WFL which contains a calss called Company. I have a second project called UI which contains a form called frmCompany. I have set a reference at UI to WFL.Company. In WFL.Company I have: 'skeleton code Public Class Company Public Event Refresh Public Sub Fetch 'do some stuff RaiseEvent Refresh End Sub End Class In UI.frmCompany I have: Public Class frmCompany 'skeleton code Private Withevents oCompany As New WFL.Company Private Sub frmCompany_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load oCompany.Fetch End Sub Private Sub oCompany_Refresh() Handles oCompany.Refresh Msgbox "I got an event" End Try End Sub End Class This is essentially how it was done in VB6. The above, however, does not work. The event is not fired. No errors occur (option strict On) What am I doing wrong here? Thanks for any help > This is essentially how it was done in VB6. The above, however, does not In a test program of mine, I put:> work. The event is not fired. No errors occur (option strict On) > What am I doing wrong here? Dim z As New frmCompany z.Test() I added the code below which is almost yours, and it worked fine. Public Class Company Public Event Refresh() Public Sub Fetch() RaiseEvent Refresh() End Sub End Class Public Class frmCompany Private WithEvents oCompany As New Company Public Sub Test() oCompany.Fetch() End Sub Private Sub oCompany_Refresh() Handles oCompany.Refresh MsgBox("I got an event") End Sub End Class So, you have your objects and events essentially correct. Put some breakpoints at places in your code to see what if anything is actually being executed.
Re-post, Help really needed here ! Dataview binded to Textbox for edits, I can't save the change.
Create a custom collection Drag and Drop to SysTray ? array in dataset Waiting for a process/program to start COBOL Packed decimal converter to VB decimal Capture and redirect TCP traffic filewatcher file modification updating listbox with database update computer properties in vb.net |
|||||||||||||||||||||||