Hi,
I have created a usercontrol, a grid control essentially. Within it I
have a class: clsGridRecord. I have coded the events such that when a
user clicks on the grid, say, the events occur on the parent form. This
is fine.
The problem occurs when I want to raise an event for a user clicking on
one of the clsRecords which are on the grid. So I've placed:
Public Event GridRecordClicked(ByVal rec As clsGridRecord,
ByVal e As EventArgs)
within the control scope and I can raise this from within the control.
However, if I try and raise it from within the control's class I get an
error: "GridRecordClicked is not an event of...[RootName space]'
Code as follows:
Private Sub clsGridRecord_MouseClick(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
'I need to raise an event, ideally within the ctlGrid
RaiseEvent Me.GridOwner.GridRecordClicked(me,e) 'doesn't work
End Sub
OK - I suppose I'm not allowed to raise the control's events. Indeed I
think I found something mentioned to this effect on this NG and read
that this could maybe be resolved using reflection. (Yikes).
The below workaround is a little convoluted (required an extra procedure
in between) but it's very simple so...
QUESTION: It works so what's wrong with it - why not do this instead of
reflection. Am I missing something obvious (other than it's a little
clumsy)?
'--------scope of ctlGrid start ------
'this is the event exposed to the parent form
Public Event GridRecordClicked(various args)
Private Sub evGridRecordClick(various args)
RaiseEvent GridRecordClicked(various args)
End Sub
'--------scope of clsGridRecord start ------
Private Sub clsGridRecord_MouseClick(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
'call proc to raise the event
evGridRecordClick (various args)
End Sub
'--------scope of clsGridRecord end ------
'--------scope of ctlGridend end ------
Many thanks