access events of form in UserControl

Thread Solved

Join Date: Feb 2009
Posts: 4
Reputation: vtelebyteM is an unknown quantity at this point 
Solved Threads: 0
vtelebyteM vtelebyteM is offline Offline
Newbie Poster

access events of form in UserControl

 
0
  #1
Feb 24th, 2009
access events of form in UserControl
i have
1)User control with one MSFlexGrid on it
2)Form to place user control
3)Some form's own control
i dont know how many controls are there under form
i have to place them in grid columns (eg. combobox in grid to provide its service)
now problem is if i place any control in grid after i LostFocus from that control i need to palce the value present in control in grid.
i cannot ask to write LostFocus function to my UserControl user or any programmer so i must have provision to catch events of controls available on form.
let's make question more simple
i need to access events of controls present on form in userControl without any code in form
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 509
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 88
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: access events of form in UserControl

 
0
  #2
Feb 24th, 2009
Hi, U can use Usercontrol.Parent Property get the Parent object and use WithEvents keyword to capture the Parent events

  1. 'In UserControl
  2. Option Explicit
  3.  
  4. Dim WithEvents mParent As Form
  5.  
  6. Private Sub mParent_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  7. MsgBox "Down"
  8. End Sub
  9.  
  10. Public Sub SetParent(mParentForm As Form)
  11. Set mParent = mParentForm
  12. End Sub
  13.  
  14. Private Sub UserControl_Show()
  15. If TypeOf UserControl.Parent Is Form Then
  16. Set mParent = UserControl.Parent
  17. End If
  18. End Sub

Now your usercontrol receive the messages if its parent is form.
KSG
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 4
Reputation: vtelebyteM is an unknown quantity at this point 
Solved Threads: 0
vtelebyteM vtelebyteM is offline Offline
Newbie Poster

Re: access events of form in UserControl

 
0
  #3
Feb 25th, 2009
thanks for code.....
i tried same thing & it works......
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC