[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

CommandBarControl.delete() not working as expected

Posted on 2011-02-16
3
Medium Priority
?
740 Views
Last Modified: 2012-05-11
Testing out the CommandBarControl.Delete() method on addin_shutdown in a Word add-in app.

I want to add a button during startup and then delete it during shutdown. Problem happens when I rerun the addin application, I do a check to see if the CommandBarButton control is there and it always is.

The delete(false) procedure seems to remove the commandbarbutton from the commandbars collection, but when I restart the add-in to debug it reappears.

It is not working like I think it should. Does anyone have any suggestions as to how to properly dispose of a commandbarcontrol forever? I thought giving the delete method a temporary parameter of false would do the trick but not so.

Thanks in advance,
Mel
Microsoft.Office.Core.CommandBar cellbar;

  private void ThisAddIn_Startup(object sender, System.EventArgs e)
  {
   cellbar = Application.CommandBars["Text"];
   Microsoft.Office.Core.CommandBarButton button = (Microsoft.Office.Core.CommandBarButton)cellbar.FindControl(Microsoft.Office.Core.MsoControlType.msoControlButton, 1, "MYRIGHTCLICKMENU", missing, missing);
   if (button == null)
   {
    // add the button     
    button = (Microsoft.Office.Core.CommandBarButton)cellbar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, 1, missing, missing, true);
    button.Caption = "My Right Click Menu Item";
    button.BeginGroup = true;
    button.Tag = "MYRIGHTCLICKMENU";
   }
  }

  private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
  {
   Microsoft.Office.Core.CommandBarButton button = (Microsoft.Office.Core.CommandBarButton)cellbar.FindControl(Microsoft.Office.Core.MsoControlType.msoControlButton, 1, "MYRIGHTCLICKMENU", missing, missing);
   object val = false;
   button.Delete(val);
  }

Open in new window

0
Comment
Question by:rotovibe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Expert Comment

by:Sudhakar Pulivarthi
ID: 34923454
Hi,
Please check out the conversation which helps to ur requirement.
http://social.msdn.microsoft.com/Forums/en/vsx/thread/8fff7d90-7867-4608-a8b6-ba9362d91411
0
 
LVL 11

Expert Comment

by:Sudhakar Pulivarthi
ID: 34923459

Check this notes on how to perform the actions by Carlos J. Quintero:
http://www.mztools.com/articles/2005/mz2005003.aspx
0
 
LVL 4

Accepted Solution

by:
jmdion earned 2000 total points
ID: 34926269
I gave a quick look at my code for an add-in I wrote 2 years ago. This is what I understand/remember.

When you remove the CommandBarButton form the collection, it is not removed from Normal.dot.  All you can do is check if the button is present and make it hidden.

If you want more control then you must create you own Application.CustomizationContext by creating your own MyAddInName.dot file (and add it to the Templates collection).  You can create it and delete it at Startup() and ShutDown() if you don't want to confuse the users. This file will never be used as a real template but you need it anyway because you can't create a CustomizationContext without a template.  This is also better because there is less chance of interference if other addins store their customizations in Normal.dot or if Normal.dot becomes corrupt.

Besides the reference on MSDN Library on CustomizationContext, you can google for explanations on this topic by "Cindy Meister" or "Jonathan West".



0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question