Adding a context menu item to the calendar view in Outlook 2010-2013

Add-in Express™ Support Service
That's what is more important than anything else

Adding a context menu item to the calendar view in Outlook 2010-2013
 
BluePosition


Guest


Hi,

I'm trying to add a button to the context menu displaying when the user right clicks and appointment/meeting in the calendar view in Outlook.
The button should only be visible if some conditions are true.

I have followed this guide: http://www.add-in-express.com/creating-addins-blog/2013/05/13/customizing-outlook-main-menu-context-menus-backstage-view/#context-menu
Which is fine - but this only lets me add the button to the email view context menu.

Is it possible to listen to an event like ContextMenuBefore_AddControls which worked for Outlook 2007?

Thanks,
Nicklas
Posted 24 Feb, 2014 03:48:59 Top
Andrei Smolin


Add-in Express team


Posts: 19174
Joined: 2006-05-11
Hello Nicklas,

That link applies to using commandbar-style controls. They can be used in Outlook 2007-2010; they've stopped supporting such controls in Outlook 2013.

For Outlook 2010-2013 you use ribbon context menus.

[CODE]this.components = new System.ComponentModel.Container();
this.adxRibbonContextMenu1 = new AddinExpress.MSO.ADXRibbonContextMenu(this.components);
this.adxRibbonButton1 = new AddinExpress.MSO.ADXRibbonButton(this.components);
//
// adxRibbonContextMenu1
//
this.adxRibbonContextMenu1.ContextMenuNames.AddRange(new string[] {
"Outlook.Explorer.ContextMenuCalendarItem",
"Outlook.Explorer.ContextMenuCalendarView",
"Outlook.Explorer.ContextMenuMultipleItems"});
this.adxRibbonContextMenu1.Controls.Add(this.adxRibbonButton1);
this.adxRibbonContextMenu1.Ribbons = AddinExpress.MSO.ADXRibbons.msrOutlookExplorer;
//
// adxRibbonButton1
//
this.adxRibbonButton1.Caption = "adxRibbonButton1";
this.adxRibbonButton1.Id = "adxRibbonButton_4ebbd97c5b104d668b9b19c1e91eddf2";
this.adxRibbonButton1.ImageTransparentColor = System.Drawing.Color.Transparent;
this.adxRibbonButton1.Ribbons = AddinExpress.MSO.ADXRibbons.msrOutlookExplorer;[QUOTE]

The settings above show the ribbon button in the context menu that opens when you right-click an appointment ("ContextMenuCalendarItem"), a date selection ("ContextMenuCalendarView") or selected items ("ContextMenuMultipleItems"). To control the visibility of the button in the context menu, you intercept the PropertyChanging event of the button. In the event handler, when e.PropertyType = ADXRibbonControlPropertyType.Visible, you verify the condition and set e.Value to true/false. To verify the condition, you retrieve information about the right-clicked object(s) as recommended in the section Determining a Ribbon Control's Context of the manual, see the PDF file in the folder {Add-in Express}\Docs on your development PC (you can also download it http://www.add-in-express.com/downloads/documentation.php).

Hope this helps.


Andrei Smolin
Add-in Express Team Leader
Posted 24 Feb, 2014 07:38:49 Top
BluePosition


Guest


Thank you, that's exactly what I needed.

However, looking in the PDF I can't seem to find anything related to how I get the current selected Item when the user right clicks an appointment in the calendar.

I have looked in the section Determining a Ribbon Control's Context, but this only says to get the e.Context and by debugging it seems that the e.Context is a Outlook Explorer object and from there I can't seem to find how to get the selected item.

Further help is much appreciated.

Thanks
Posted 24 Feb, 2014 11:49:05 Top
BluePosition


Guest


Hi again,

I found a solution:
OutlookApp.ActiveExplorer().Selection.Count > 0
Posted 24 Feb, 2014 12:53:05 Top
Andrei Smolin


Add-in Express team


Posts: 19174
Joined: 2006-05-11
BluePosition writes:
I have looked in the section Determining a Ribbon Control's Context, but this only says to get the e.Context and by debugging it seems that the e.Context is a Outlook Explorer object


I use Microsoft.VisualBasic.Information.TypeName() as suggested in the manual to get the following types behind e.Context (Outlook 2013):

- right-clicking an appointment (context menu name = "ContextMenuCalendarItem") - Selection
- right-clicking several items (context menu name = "ContextMenuMultipleItems") - Selection
- right-clicking a date or date selection (context menu name = "ContextMenuCalendarView") - CalendarView

You need to get selected items from the context object - just cast e.Context to Selection. Getting selected items using OutlookApp.ActiveExplorer().Selection may produce different (incorrect) results.


Andrei Smolin
Add-in Express Team Leader
Posted 25 Feb, 2014 04:30:34 Top