|
-
Nov 14th, 2005, 10:51 AM
#1
Thread Starter
Addicted Member
Calling a procedure from a UserControl?
If I have a UserControl (UsrCtlDate) which contains a textbox (txtDate_D), how do I call a procedure which lies in the active form when the event "txtDate_D.validating" is fired?
I tried "Form.ActiveForm.Procedure1" which doesn't work. I also tried declaring a string which contains the name of the current active form, and then using If statements with specific Form names (e.g. If CurrentForm = "frmData" then frmData.Procedure1), which also didn't work. Lastly, I tried UserControl.Parent.Procedure1, which also failed.
How can I call a procedure which lies in the active form from the UserControl?
-
Nov 14th, 2005, 10:59 AM
#2
Re: Calling a procedure from a UserControl?
How about you create a new Event in your user control and you fire the event when you need to. Then in your Main form, you create an Event handler for your event and fire your procedure.
-
Nov 14th, 2005, 11:16 AM
#3
Thread Starter
Addicted Member
Re: Calling a procedure from a UserControl?
Sorry, please elaborate? This is what I have currently:
<UsrCtlDate>
VB Code:
Private Sub txtDate_D_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtDate_D.Validating
frmData_TextBox1Validated = Module_txtDates_All_Validating(sender, Me, e)
[b]'Form.ActiveForm.LabelInfoChange(frmData_LabelChangeIndex)[/b]
End Sub
<frmPrint>
VB Code:
Public Sub LabelInfoChange(ByVal LabelIndex As Integer, Optional ByVal IsDefault As Boolean = False)
'<Stuff to change the label on frmPrint>
End Sub
<frmData>
VB Code:
Public Sub LabelInfoChange(ByVal LabelIndex As Integer, Optional ByVal IsDefault As Boolean = False)
'<Stuff to change the label on frmData>
End Sub
(The bold code is what I want done, but does not work)
-
Nov 14th, 2005, 11:23 AM
#4
Re: Calling a procedure from a UserControl?
Add an event to your UserControl:
VB Code:
Public Event AfterValidated()
Private Sub txtDate_D_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtDate_D.Validating
frmData_TextBox1Validated = Module_txtDates_All_Validating(sender, Me, e)
RaiseEvent AfterValidated()
End Sub
Then wherever you have your usercontrol, you now have an AfterValidated event, where you can then call your LabelInfoChange code.
VB Code:
Private Sub UserControl12_AfterValidated() Handles UserControl12.AfterValidated
LabelInfoChange(Me.LabelChangeIndex)
End Sub
-
Nov 14th, 2005, 12:02 PM
#5
Thread Starter
Addicted Member
Re: Calling a procedure from a UserControl?
Thanks, I think it's working fine now
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|