PC Review


Reply
Thread Tools Rate Thread

Click event on menu item is lost after first time firing of the event

 
 
mayuresh.kasture@gmail.com
Guest
Posts: n/a
 
      2nd Apr 2007
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.msoControlPopup,
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(this.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(this.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

 
Reply With Quote
 
 
 
 
mayuresh.kasture@gmail.com
Guest
Posts: n/a
 
      2nd Apr 2007
On Apr 2, 4:10 pm, mayuresh.kast...@gmail.com 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.msoControlPopup,
> 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(this.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(this.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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access 2003 Click Event not firing first time. Slick Willy Microsoft Access 6 14th Apr 2009 03:24 AM
firing button click event before page load event.....???? GauravGupta Microsoft ASP .NET 3 2nd Jul 2007 01:14 PM
menu click event not firing Jesse Aufiero Microsoft Dot NET Compact Framework 1 29th Dec 2005 08:21 AM
Catching menu item click event Jill Microsoft Outlook Program Addins 2 21st Sep 2005 07:34 AM
How to allow click event on menu item parent =?Utf-8?B?TWFydHkgQ3J1aXNl?= Microsoft VB .NET 1 10th Aug 2005 02:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:29 AM.