Hi
I have created a collection of Excel CommandBarButtons on workBook_open event and added to my CommandBar.while iterating through a loop i have also assigned event handler for each buttons.
I am getting a funny output when exceuting this>
1) when for the first timei open the Excel workbook all buttons are loaded perfectly on the excel command bar.
2) For the first time if i click any of the buttons(only once)it worked and respective output is shown in a window form.
3) Next time after closing the form if i click ,i am not getting any event.(No event takes place)
4)Last commanbar button whcich has created at the last iterate , fires the event on every click.
Can anybody suggest me where i am doing the mistake ???
MyCode Below:
commandBar = applicationObject.CommandBars.Add(
"ExcelCommadBar", 1, System.Reflection.Missing.Value, true);
ButtonInfo=ParseXML(); //ButtonInfo is a DataTable
for(int rowCount=0;rowCount<ButtonInfo.Rows.Count;rowCount++)
{
_btnNewBrowser = (Microsoft.Office.Core.
CommandBarButton)
commandBar.Controls.Add(1,
System.Reflection.
Missing.Value,
System.Reflection.
Missing.Value,
System.Reflection.
Missing.Value,
System.Reflection.
Missing.Value);
_btnNewBrowser.Caption = ButtonInfo.Rows[rowCount].ItemArray[1].ToString();
_btnNewBrowser.Style = Microsoft.Office.Core.
MsoButtonStyle.msoButtonIconAndCaption;
_btnNewBrowser.Click +=
new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(_ButtonWorkSheet_Click);
}
Thanks
__Das