akshayakrsh
New Member
- Joined
- Mar 19, 2009
- Messages
- 1
Hi
please see the following code.
I have create two custom CommandBarPopup on the context menu each with 2 CommandBarButton (with click events on them).
After run my solution, I am able to see my custom options in the Context Menu.
I am facing 2 problems:
1. The major problem is, when I run the solution, I click on one of the 4 CommandBarButtons and the click event is called, doing the assigned process. But, if click on any of the CommandBarButtons after that, my click events dont get called at all, unless restart executing my project.
But, even after restarting the project, only the CommandBarButton click event works only for the first time, no matter how much I try.
Consider I have 2 CommandBarPopups - A and B.
A has A1 and A2 as CommandBarButtons
B has B1 and B2 as CommandBarButtons
When I start the project and I click on any button A1, A2, B1 or B2, the respective button's click event will work. But after that, if I click on any of the buttons A1, A2, B1 or B2, nothing works.
Please tell me, what am I doing wrong here?
2. After I close my project, and open excel directly, still I can see the custom options in the context menu, even though I do the RESET() method on all the command bars. Can you tell whats wrong here?
THANKS A TON.
please see the following code.
I have create two custom CommandBarPopup on the context menu each with 2 CommandBarButton (with click events on them).
After run my solution, I am able to see my custom options in the Context Menu.
I am facing 2 problems:
1. The major problem is, when I run the solution, I click on one of the 4 CommandBarButtons and the click event is called, doing the assigned process. But, if click on any of the CommandBarButtons after that, my click events dont get called at all, unless restart executing my project.
But, even after restarting the project, only the CommandBarButton click event works only for the first time, no matter how much I try.
Consider I have 2 CommandBarPopups - A and B.
A has A1 and A2 as CommandBarButtons
B has B1 and B2 as CommandBarButtons
When I start the project and I click on any button A1, A2, B1 or B2, the respective button's click event will work. But after that, if I click on any of the buttons A1, A2, B1 or B2, nothing works.
Please tell me, what am I doing wrong here?
2. After I close my project, and open excel directly, still I can see the custom options in the context menu, even though I do the RESET() method on all the command bars. Can you tell whats wrong here?
Code:
private void ThisAddIn_Startup(object sender, EventArgs e)
{
InitializeMembers();
InsertContextMenu();
}
private void ThisAddIn_Shutdown(object sender, EventArgs e)
{
ResetCommandBars();
}
/// <summary>
/// Initializes and insert the custom context menu items
/// </summary>
void InsertContextMenu()
{
var commandBarTools = Application.CommandBars["Cell"];
//add Source Menu to the Context Menu
var cmdBarTools_Src = commandBarTools.Controls.Add(MsoControlType.msoControlPopup, 1, "", 1, true);
cmdBarTools_Src.Visible = true;
cmdBarTools_Src.Caption = "Source";
//Select Source1 sub-option
var popup_src1 = (CommandBarPopup)cmdBarTools_Src;
var bar_src1 = popup_src1.CommandBar;
var cmdBarControl_src1 = bar_src1.Controls.Add(MsoControlType.msoControlButton, 1, "", 1, true);
cmdBarControl_src1.Caption = "Select Source 1";
var button_src1 = (CommandBarButton)cmdBarControl_src1;
button_src1.Click += button_src1_Click;
//Select Source2 sub-option
var popup_src2 = (CommandBarPopup)cmdBarTools_Src;
var bar_src2 = popup_src2.CommandBar;
var cmdBarControl_src2 = bar_src2.Controls.Add(MsoControlType.msoControlButton, 1, "", 2, true);
cmdBarControl_src2.Caption = "Select Source 2";
var button_src2 = (CommandBarButton)cmdBarControl_src2;
button_src2.Click += button_src2_Click;
//Select Mapping sub-option
var popup_map = (CommandBarPopup)cmdBarTools_Src;
var bar_map = popup_map.CommandBar;
var cmdBarControl_map = bar_map.Controls.Add(MsoControlType.msoControlButton, 1, "", 3, true);
cmdBarControl_map.Caption = "Select Mapping";
var button_map = (CommandBarButton)cmdBarControl_map;
button_map.Click += button_map_Click;
//add Constraints Menu to the Context Menu
var cmdBarTools_Cnst = commandBarTools.Controls.Add(MsoControlType.msoControlPopup, 1, "", 2, true);
cmdBarTools_Cnst.Visible = true;
cmdBarTools_Cnst.Caption = "Constraints";
//Select Add\Edit Constraint sub-option
var popup_addCstr = (CommandBarPopup)cmdBarTools_Cnst;
var bar_addCstr = popup_addCstr.CommandBar;
var cmdBarControl_addCstr = bar_addCstr.Controls.Add(MsoControlType.msoControlButton, 1, "", 1, true);
cmdBarControl_addCstr.Caption = "Add\\Edit Constraint";
var button_addCstr = (CommandBarButton)cmdBarControl_addCstr;
button_addCstr.Click += button_addCstr_Click;
//Select Delete Constraint
var popup_delCstr = (CommandBarPopup)cmdBarTools_Cnst;
var bar_delCstr = popup_delCstr.CommandBar;
var cmdBarControl_delCstr = bar_delCstr.Controls.Add(MsoControlType.msoControlButton, 1, "", 2, true);
cmdBarControl_delCstr.Caption = "Delete Constraint";
var button_delCstr = (CommandBarButton)cmdBarControl_delCstr;
button_delCstr.Click += button_delCstr_Click;
}
private void ResetCommandBars()
{
for (var i = 1; i <= Application.CommandBars.Count; i++)
Application.CommandBars[i].Reset();
}
THANKS A TON.