p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB How-To (http://p2p.wrox.com/forumdisplay.php?f=78)
-   -   FireEvent from userControl (http://p2p.wrox.com/showthread.php?t=66915)

dhoyle March 26th, 2008 11:05 AM

FireEvent from userControl
 
I have a windows app and I am required to call various form designs so I used UserControls to do this. However, I have a Usercontrol1 which displays a UserControl2 and there is an Event in UserControl2 which should fire and event in UserControl1.

I have tried everything. I have used the AddHandler and yes I do get back to the correct function but it does not fire the event.

Thanks a ton!


gbianchi March 26th, 2008 04:11 PM

Hi there..

An easy way is to have an event in usercontrol2 and control that event from usercontrol1.

You raise the event when the usercontrol2 event raise. Do I explain it clear?

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========

dhoyle March 26th, 2008 05:02 PM

Actually I have 2 userControls and 2 classes I use.

UserControl2 has the following code which is launched when the textbox MTB_PkgCount is changed.

Dim PkgCount As Integer = MTB_PkgCount.Text
       If Val(MTB_PkgCount.Text) > 1 Then
                CB_Identical.Visible = True

            Dim myFireAlarm As New FireAlarm()
            Dim myFireHandler As New FireHandlerClass(myFireAlarm, e)
            myFireAlarm.ActivateFireAlarm(PkgCount, e)


It Does reach the function PkgCount_Click located in the UserControl1 and steps through with no error but nothing happens.

The 2 classes are FireAlarm & FireHandler are the following


Public Class FireAlarm
    Delegate Sub PkgCount_Click(ByVal PkgCount As Integer, ByVal e As System.Windows.Forms.KeyEventArgs)
    Public Event FireEvent As PkgCount_Click

    Public Sub ActivateFireAlarm(ByVal PkgCount As Integer, ByVal e As System.Windows.Forms.KeyEventArgs)
        RaiseEvent FireEvent(PkgCount, e)
    End Sub

End Class

Class FireHandlerClass
    Public obj As New force.ucShip2

    Public Sub New(ByVal fireAlarm As FireAlarm, ByVal e As System.Windows.Forms.KeyEventArgs)
        AddHandler fireAlarm.FireEvent, AddressOf obj.PkgCount_Click
    End Sub
End Class


Thanks for your reply!!!


gbianchi March 26th, 2008 09:11 PM

so.. where is your problem there?

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========

dhoyle March 27th, 2008 08:04 AM

I don't know the FireEvent raises the delegate and I do reach the function PkgCount_Click and there is nor errors in PkgCount_Click but nothing ever happens.

Thanks,
David


gbianchi March 27th, 2008 08:20 AM

Are you sure that you are reaching the same handler that you are looking for? maybe you are raising the event in a new object (and not your parent)...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========

dhoyle March 27th, 2008 09:02 AM

Good Point.
I know I am firing the event in UserControl2 and I am getting back to the function located in UserControl1 but then nothing happens. I was guessing it might be a focus issue. but I have tried every combination of focus() I can think of to no avail.

Thanks,
David


gbianchi March 27th, 2008 09:30 AM

Well.. try looking for your parent control and raise the event there (or to make it simple, just call a function that you know exist)...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========

dhoyle May 14th, 2008 02:51 PM

I am posting the solution cause I am sure others may need it also.
When you have usercontrols within other usercontrols and need to make the control do something, you have to loop to first find the control.

ucSHip2 as a usercontrol loaded into the MainForm. I needed to change the text within the BindingNavigator1 which was located in ucShip2. I use a property Biz.RowSelectz to determine what the text should be.


Dim ctr2 As Control
        For Each ctr2 In MainForm.MainFormPanel.Controls
            If TypeOf ctr2 Is ucShip2 Then
                DirectCast(ctr2, ucShip2).BindingNavigator1.Focus()
                DirectCast(ctr2, ucShip2).BindingNavigator1.PositionItem.Text = Biz.RowSelectz + 1

            End If
        Next ctr2



All times are GMT -4. The time now is 01:49 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.