Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Click event on menu item is lost after first time firing of the event

Hi,

I am using VSTO SE for excel development. I am trying to add menu
items to context menu. Well, I can add it but some how the menu item
loses the click event when it is clicked once i.e. click event handler
is invoked only once.

Here is the code fragment that adds menu item,

Office.CommandBarPopup Ctrl1;
Office.CommandBarButton Ctrl2, Ctrl3;

Ctrl1 =
(Office.CommandBarPopup)Application.CommandBars["Cell"].Controls.Add(Office.MsoControlType.msoControlPopu p,
1, null, 1, true);
Ctrl1.Caption = "Menu Item";


Ctrl2 =
(Office.CommandBarButton)Ctrl1.Controls.Add(Office .MsoControlType.msoControlButton,
1, null, 1, true);
Ctrl2.Visible = true;
Ctrl2.Caption = "C# Test Button 1";
Ctrl2.Tag = "AddinTag1";
Ctrl2.Click += new
Office._CommandBarButtonEvents_ClickEventHandler(t his.moBtn_Click);


Ctrl3 =
(Office.CommandBarButton)Ctrl1.Controls.Add(Office .MsoControlType.msoControlButton,
1, null, 1, true);
Ctrl3.Visible = true;
Ctrl3.Caption = "C# Test Button 2";
Ctrl3.Tag = "AddinTag2";
Ctrl3.Click += new
Office._CommandBarButtonEvents_ClickEventHandler(t his.moBtn_Click1);

These are event handlers,

private void moBtn_Click(Office.CommandBarButton Ctrl, ref
bool CancelDefault)
{

MessageBox.Show(Ctrl.Tag);
Trace.Write("moBtn_Click - " + Ctrl.Tag);
}

private void moBtn_Click1(Office.CommandBarButton Ctrl, ref
bool CancelDefault)
{
MessageBox.Show(Ctrl.Tag);
Trace.Write("moBtn_Click - " + Ctrl.Tag);
}

Can anybody tell me what is happening here?

Thanks in advance

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Click event on menu item is lost after first time firing of the event

On Apr 2, 4:10 pm, wrote:
Hi,

I am using VSTO SE for excel development. I am trying to add menu
items to context menu. Well, I can add it but some how the menu item
loses the click event when it is clicked once i.e. click event handler
is invoked only once.

Here is the code fragment that adds menu item,

Office.CommandBarPopup Ctrl1;
Office.CommandBarButton Ctrl2, Ctrl3;

Ctrl1 =
(Office.CommandBarPopup)Application.CommandBars["Cell"].Controls.Add(Office*.MsoControlType.msoControlPop up,
1, null, 1, true);
Ctrl1.Caption = "Menu Item";

Ctrl2 =
(Office.CommandBarButton)Ctrl1.Controls.Add(Office .MsoControlType.msoContro*lButton,
1, null, 1, true);
Ctrl2.Visible = true;
Ctrl2.Caption = "C# Test Button 1";
Ctrl2.Tag = "AddinTag1";
Ctrl2.Click += new
Office._CommandBarButtonEvents_ClickEventHandler(t his.moBtn_Click);

Ctrl3 =
(Office.CommandBarButton)Ctrl1.Controls.Add(Office .MsoControlType.msoContro*lButton,
1, null, 1, true);
Ctrl3.Visible = true;
Ctrl3.Caption = "C# Test Button 2";
Ctrl3.Tag = "AddinTag2";
Ctrl3.Click += new
Office._CommandBarButtonEvents_ClickEventHandler(t his.moBtn_Click1);

These are event handlers,

private void moBtn_Click(Office.CommandBarButton Ctrl, ref
bool CancelDefault)
{

MessageBox.Show(Ctrl.Tag);
Trace.Write("moBtn_Click - " + Ctrl.Tag);
}

private void moBtn_Click1(Office.CommandBarButton Ctrl, ref
bool CancelDefault)
{
MessageBox.Show(Ctrl.Tag);
Trace.Write("moBtn_Click - " + Ctrl.Tag);
}

Can anybody tell me what is happening here?

Thanks in advance


Hey, problem is solved. Just declared Ctrl1,Ctrl2 and Ctrl3 as members
of class rather than local to the function.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combobox - can't get click event to run for first item in the list Dale Excel Programming 3 August 9th 06 02:55 AM
Click Event taking time William Benson[_2_] Excel Programming 2 July 20th 05 08:42 PM
OnTime event not firing in Workbook_Open event procedure GingerTommy Excel Programming 0 September 24th 03 03:18 PM
Triggering click event of a menu in vba steve Excel Programming 4 August 19th 03 06:17 PM
Triggering click event of a menu in vba Tom Ogilvy Excel Programming 0 August 18th 03 07:51 PM


All times are GMT +1. The time now is 08:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"