Alex,
Thanks for the reply. I have a function which builds the menu - creates a
new ContextMenu, adds MenuItems and then calls AddHandler for each menu
item. This "buildmenu" function is called in the AfterSelect event of a
TreeView...like MyTreeView.ContextMenu = BuildMenuFunction()
What I'm wondering is if before I call the BuildMenuFunction, should I
iterate through the current ContextMenu and call RemoveHandler for each
MenuItem? Or will VB do this for me automatically. I've attached the
BuildMenuFunction code below.
Thanks again,
Dave Taylor
PERI
Private Function GetPointsMenu(ByVal mr As dsSNAP.ModulesRow) As ContextMenu
Dim pr As dsSNAP.PXPointsRow, mi As MenuItem
Dim cm As New ContextMenu
Dim dr As DataRow()
Dim spr As dsConfig.SnapPointsRow
Dim bInclude As Boolean
mi = cm.MenuItems.Add("Empty")
AddHandler mi.Click, AddressOf SelectPoint
If mr Is Nothing Then Return cm 'The module is not defined yet, so just
return an "Empty" menu item
'Get the points already defined for this Unit
dr = config.SnapPoints.Select("unit_id = " & GetUnitID().ToString)
For Each pr In PX.SnapLib.PXPoints
bInclude = True
'Do the type-appropriate checks first (fastest)
'Then search the list of points only if necessary
'Check if point is appropriate type for selected module
If pr.analog <> mr.analog Then bInclude = False
If ((pr.direction = -1) And (Not mr.input)) Or ((pr.direction = 1)
And mr.input) Then bInclude = False
'Check if point is already defined, if so, then do not include it
If bInclude Then
For Each spr In dr
If spr.name = pr.name Then
bInclude = False
Exit For
End If
Next
If bInclude Then
mi = cm.MenuItems.Add(pr.name)
AddHandler mi.Click, AddressOf SelectPoint
End If
End If
Next
Return cm
End Function
[quoted text, click to view] "Alexandre Moura" <amoura@online.microsoft.com> wrote in message
news:3uLJmEPcEHA.2428@cpmsftngxa06.phx.gbl...
> I'm not sure if I understand you scenario, but there are a few questions
here - are the objects that contain the event you are handling being
collected? if so,
[quoted text, click to view] > then it depends :) the handler delegate won't be collected until the
object that contains the event it handles is collected, so if the object can
throw events
[quoted text, click to view] > after you've eliminated any references to it, then you should call
removehandler.
> If the objects that contain the event aren't being collected, then you'll
be adding more and more handlers (it's addictive), so you should call
removehandler
[quoted text, click to view] > for each tyme you add a handler.
>
> Hope that helps, Alex (MS VB QA)
>