Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 26th, 2008, 11:05 AM
Registered User
 
Join Date: Mar 2008
Location: Eads, TN, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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!

Reply With Quote
  #2 (permalink)  
Old March 26th, 2008, 04:11 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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
================================================== =========
Reply With Quote
  #3 (permalink)  
Old March 26th, 2008, 05:02 PM
Registered User
 
Join Date: Mar 2008
Location: Eads, TN, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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!!!

Reply With Quote
  #4 (permalink)  
Old March 26th, 2008, 09:11 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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
================================================== =========
Reply With Quote
  #5 (permalink)  
Old March 27th, 2008, 08:04 AM
Registered User
 
Join Date: Mar 2008
Location: Eads, TN, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #6 (permalink)  
Old March 27th, 2008, 08:20 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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
================================================== =========
Reply With Quote
  #7 (permalink)  
Old March 27th, 2008, 09:02 AM
Registered User
 
Join Date: Mar 2008
Location: Eads, TN, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #8 (permalink)  
Old March 27th, 2008, 09:30 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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
================================================== =========
Reply With Quote
  #9 (permalink)  
Old May 14th, 2008, 02:51 PM
Registered User
 
Join Date: Mar 2008
Location: Eads, TN, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ArrayList with UserControl rhd110 General .NET 2 August 12th, 2007 12:29 PM
usercontrol and javascript Hanch ASP.NET 2.0 Basics 1 March 7th, 2007 08:38 AM
Usercontrol properties. chakravarthy_vb General .NET 1 March 31st, 2005 02:39 AM
Refresh UserControl jpfree71 ASP.NET 1.0 and 1.1 Basics 3 August 17th, 2004 12:31 PM
a usercontrol problem csc820203 C# 2 July 10th, 2004 10:55 AM



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


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