Click to See Complete Forum and Search --> : ObjectEvent not firing, please help!
Elvenstone
Feb 6th, 2009, 09:28 AM
Hi all!
I built a usercontrol (JaNee), which fires an event called "Changed" when the optionbutton it contains is clicked.
The control is added to a parent usercontrol at runtime using Controls.add, like this:
Private WithEvents m_Ctl As VBControlExtender
...
Set m_Ctl = Controls.Add("MyControls.JaNee", "jnValue")
m_Ctl.Visible = True
I use the following to catch the event:
Private Sub m_Ctl_ObjectEvent(Info As EventInfo)
If Info.Name = "Changed" Then
MsgBox "Hello World!"
End If
End Sub
This works fine for other usercontrols I've built, but for some particular reason, the ObjectEvent is not fired for this usercontrol.
Any ideas guys? There has to be a logical explanation.
LaVolpe
Feb 7th, 2009, 05:51 PM
This is going to sound like a couple of stupid questions.
1. Are sure the control loaded? Have you checked with a statement similar to:
If m_Ctl Is Nothing Then MsgBox "Failed to load JaNee"
2. Are you sure the option button is firing the event? Is there any code in the option button's click event that is being tested and doesn't fire the event for some cases?
3. Is the parent usercontrol & the JaNee controls enabled?
If you simply do a Debug.Print Info.Name, do you get other events from the dynamically loaded usercontrol?
Elvenstone
Feb 9th, 2009, 04:44 AM
I do not regard your questions stupid, so here's the answers:
1. Are sure the control loaded?
Yes, the control is visible.
2. Are you sure the option button is firing the event?
Yes, stepping through the code it executes the RaiseEvent statement, but the Changed event is not captured by the ObjectEvent handler.
3. Is the parent usercontrol & the JaNee controls enabled?
Yes, all enabled properties are set to True.
4. If you simply do a Debug.Print Info.Name, do you get other events from the dynamically loaded usercontrol?
No, the "Changed" event is the only one event it fires.
Thanks for thinking along. Any more suggestions?
Elvenstone
Feb 9th, 2009, 07:31 AM
I added a new usercontrol which raises "Changed" when clicked.
And as before the event is raised, but not handled by it's parent.
I compared the usercontrol's properties to one that does work, but they are an exact match. Therefor, I am beginning to think it has something to do with the project properties. Alas, no differences found there either.
As an old Hobbit would say: Confusticate and bebother VB!
LaVolpe
Feb 9th, 2009, 07:50 AM
I tried to play along. I created a uc (uc#1) that had a couple of option buttons that raised a change event & compiled it. In IDE, I added a new usercontrol (uc#2) that dynamically loaded uc#1, using Controls.Add(...). When the option button was clicked, I did get the event in uc#2. Last dumb question: SP6 installed? I am running out of dumb questions & good ideas.
Elvenstone
Feb 9th, 2009, 08:16 AM
SP6 is installed allright.
I added the usercontrol that fires the event to the parent control's project and it works fine now.
But off course, this not a fancy solution. Maybe if I reach the brilliant zone in the future, which I doubt, I will add the solution to this thread. Unless anyone else figures this thing out. :rolleyes:
Thanks for your help. :thumb: I'll add one to your rep.
LaVolpe
Feb 9th, 2009, 09:22 AM
If I understand you correctly the parent.child relationship looks like this:
FormX.UserCtrl1.JaNee
UserCtrl1 does get JaNee's events? If so, you want JaNee to send the event directly to the form? I don't think that is doable. JaNee would trigger events to UserCtrl1 and UserCtrl1 may need to forward/propogate those events to FormX
The child parent relationship described above is what I used to try to replicate the problem. I may not have replicated the scenario correctly?
Elvenstone
Feb 9th, 2009, 10:05 AM
Nope. Just plain and simple UserCtrl1 handles JaNee's events.
The JaNee is loaded runtime.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.