Repopulate comboboxes on form1 from event on form2

  • Thread starter Thread starter Randy Hentz
  • Start date Start date
R

Randy Hentz

I have done this in regular .net with an event on form2 that runs a
sub on form1. Only proplem is I can't get .net to raise the event.
Am I going about this the right way? Should I be using threading or
something?

Thanks In Advance
 
You could have form1 create an instance of form2 and before you call form2's
Show or ShowDialog method hook into a custom event that you have defined on
form2. Then if you need to pass information back from form2 to form1 you
could do that using a custom EventArgs class passed through the event to
form1. Or is it something more complicated than this?
 
Ok, I am new to this I understand creating an instance of form2 on
form one Dim blah as new form2. But how do I hook into a custom event
on form2 (I have one on form2) but hook into into it from form1? I do
have an event on form2 and the event handler code on form1 but the
event on form 2 will not fire the code on form1. The same code I used
works on .net but not compact.net.

Thanks in advance....
 
To add or remove an event handler dynamically in VB.Net you need to use the
AddHandler and RemoveHandler statements, respectively. So, for example, from
inside a button click event handler on Form1 you could do the following:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim myForm2 As New Form2
AddHandler myForm2.UpdateData, AddressOf Me.UpdateData
myForm2.ShowDialog()
RemoveHandler myForm2.UpdateData, AddressOf Me.UpdateData
myForm2.Dispose()
End Sub

Private Sub UpdateData(ByVal sender As Object, ByVal e As
UpdateDataEventArgs)
MessageBox.Show("UpdateData Event Raised")
End Sub
 
Back
Top