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

8 Years
Discussion Span
Last Post by vtelebyteM

Hi, U can use Usercontrol.Parent Property get the Parent object and use WithEvents keyword to capture the Parent events

'In UserControl
Option Explicit

Dim WithEvents mParent As Form

Private Sub mParent_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   MsgBox "Down"
End Sub

Public Sub SetParent(mParentForm As Form)
   Set mParent = mParentForm
End Sub

Private Sub UserControl_Show()
   If TypeOf UserControl.Parent Is Form Then
      Set mParent = UserControl.Parent
   End If
End Sub

Now your usercontrol receive the messages if its parent is form.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.