oshai
oshai

Reputation: 15355

onclick delegate is triggered only once

I am writing an outlook add-in that adds a menu to outlook. Although I set delegate to an action for the menu it seems like it is being removed after one call to the delegate - one click on the menu item. next time user clicks it is not getting to my delegate. code example:

menuCommand = (Office.CommandBarButton)cmdBarControl.Controls.Add(
Office.MsoControlType.msoControlButton, missing, missing, missing, true);

menuCommand.Caption = "&Generate weekly...";
menuCommand.Tag = "Generate";
menuCommand.FaceId = 65;

menuCommand.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(
menuCommand_Generate_Click);

menuCommand = (Office.CommandBarButton)cmdBarControl.Controls.Add(
    Office.MsoControlType.msoControlButton, missing, missing, missing, true);

menuCommand.Caption = "&About";
menuCommand.Tag = "About";
menuCommand.FaceId = 65;

menuCommand.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(
menuCommand_About_Click);
menuCommand.BeginGroup = true;

What should I do in order for the menu to trigger the action every time?

Upvotes: 1

Views: 461

Answers (1)

Jan-Peter Vos
Jan-Peter Vos

Reputation: 3197

Is menuitem a local variable? , becouse then the garbage collector might clean in up once it falls out of scope.

Try keeping the variable in a global object.

Upvotes: 1

Related Questions