F
fedebona
I have an outlook toolbar where I dynamically rebuild some buttons from a
popupMenu. To do this I call Delete Method to remove old buttons and recall
Add method to add new ones.
graphically it's all OK: old buttons disappear and new ones are correctly
visible. But Delete method probably doesn't kill the COM object that
represents the button, so the event handler associated with the button is
still alive
I tried remove event handler registration first but it gives me an error:
((Office.CommandBarButton)rootMenu.Controls[index]).Click -=
imAppsMenu_Click;
rootMenu.Controls[index].Delete(true);
The line where I try to deregister the event handler gives me a null
reference error. If I remove it, the event handler is still registered and
when I subsequently add a new button with the same event handler then the
handler is called twice....
So, what's the correct way to remove a button that has a registered event
handler from a toolbar via VSTO?
Thanks
popupMenu. To do this I call Delete Method to remove old buttons and recall
Add method to add new ones.
graphically it's all OK: old buttons disappear and new ones are correctly
visible. But Delete method probably doesn't kill the COM object that
represents the button, so the event handler associated with the button is
still alive
I tried remove event handler registration first but it gives me an error:
((Office.CommandBarButton)rootMenu.Controls[index]).Click -=
imAppsMenu_Click;
rootMenu.Controls[index].Delete(true);
The line where I try to deregister the event handler gives me a null
reference error. If I remove it, the event handler is still registered and
when I subsequently add a new button with the same event handler then the
handler is called twice....
So, what's the correct way to remove a button that has a registered event
handler from a toolbar via VSTO?
Thanks