This project has moved. For the latest updates, please go here.

Accessing Inspector events in OutlookApi

Feb 4, 2013 at 11:50 AM
Edited Feb 4, 2013 at 12:42 PM

I need to subscribe to NewInspector event of Outlook.Inspector, but OutlookApi.Application.Inspectors returns _Inspectors (without events). But in original interop assemblies it returns Inspectors with events. Also, GetActiveInspector returns _Inspector instead of Inspector.
Is it a bug or I am missing something?

And the same with CustomTaskPane. I need to use VisibleStateChangeEvent and DockPositionStateChangeEvent, but
ctpFactory.CreateCTP gives me _CustomTaskPane.
Feb 4, 2013 at 1:02 PM
I found answer myself.
_CustomTaskPane ctp;
CustomTaskPane taskPane = new CustomTaskPane(ctp, ctp.UnderlyingObject)
It seems to work. But I think it will be good to describe this in FAQ section.
Aug 13, 2013 at 11:22 AM
Edited Aug 13, 2013 at 11:50 AM
I'm also having this issue, did you find a solution to the New Inspector Event? I was trying to do something like this , but no luck because "Handles inspectors.NewInspector" doesn't find the NewInspector-Event.


OK, it's working now, although I have no idea why this didn't work previously. I just have the following (all in Addin.vb:
Shared _outlookApplication As Outlook.Application

Private WithEvents inspectors As Outlook.Inspectors

Public Sub OnStartupComplete(ByRef custom As System.Array) Implements IDTExtensibility2.OnStartupComplete
    inspectors = _outlookApplication.Inspectors
End Sub

  Private Sub inspectors_NewInspector(ByVal Inspector As Outlook.Inspector) Handles inspectors.NewInspectorEvent
    Dim mailItem As Outlook.MailItem = CType(Inspector.CurrentItem, Outlook.MailItem)
  End Sub
I'm sure I had that before, and the compiler complained that it couldn't find the NewInspectorEvent. I'm glad it works now, although I wish I knew why it didn't before.
Aug 13, 2013 at 2:06 PM
I am just experiencing exactly the same thing with the Explorers.SelectionChangeEvent. What I have done is :

Create the variable in Addin.vb
 Private WithEvents explorers As Outlook.Explorers
set the value
  Public Sub OnStartupComplete(ByRef custom As System.Array) Implements IDTExtensibility2.OnStartupComplete
    explorers = _outlookApplication.Explorers
  End Sub
add the handler
  Private Sub explorers_SelectionChange(ByVal Explorer As Outlook.Explorer) Handles explorers.SelectionChangeEvent
    'do something
  End Sub
however, the compiler claims not to be able to find explorers.SelectionChangeEvent.

Any ideas?
Aug 13, 2013 at 2:50 PM
Yes, this is the same problem. But Explorers don't have SelectionChange event. You need Explorer class.
For objects with events NetOffice have two clasess, one - with events and another - without events. For Explorer there are 2 classes:
_Explorer - without events
Explorer - with events.
Most of the time, NetOffice properties and methods return objects without events to save resources when you don't need events. But you can easily transform them into the objects with events.

This should be something like this (I din't code on for a few years, so there can be some syntax errors)

private WithEvents _explorer as Outlook.Explorer

  Public Sub OnStartupComplete(ByRef custom As System.Array) Implements IDTExtensibility2.OnStartupComplete
    dim e as Outlook._Explorer ' without events
    set e = _outlookApplication.ActiveExplorer
    set _explorer = new Explorer(explorer) ' now - with events
  End Sub

 Private Sub _explorer_SelectionChange(ByVal Explorer As Outlook.Explorer) Handles _explorer.SelectionChangeEvent
    'do something
  End Sub
Aug 13, 2013 at 3:36 PM
now it becomes all quite a bit clearer, thanks a lot!