Registering events on calendar items on startup

M

Manish

I need to register for ItemEvents_10_BeforeDeleteEventHandler,
ItemEvents_10_PropertyChangeEventHandler on any Calendar Event that is
processed by my addin. For any calendar event handled by my addin, I
mainatin the Outlook Id in a database, and also set a user-property on the
outlook appt item.

I know of 2 ways to register for these event handlers for all my calendar
items. Question is which one is better. Can you please provide some insight.

1) On startup complete, I get a list of all calendar folders and iterate
through every item in each of the folders looking for either my user-property
being set, or if the outlook id matches ones in my database. For each such
item, I register the event handlers. Problem I see here is that the add-in
might take too long to load. Im not sure how many months/years of calendar
appts are returned if I called GetDefaultFolder.

2) I register for ExplorerEvents_10_BeforeFolderSwitchEventHandler on all
acitve explorers, and if the ToFolder is of type olAppointmentItem, then I
register for this.Application.ActiveExplorer().SelectionChange += new
Outlook.ExplorerEvents_10_SelectionChangeEventHandler. Then when the user
selects an appointment Item, my callback can check if my user property is
set, and if so register for the property-change and delete event handlers.
problem with this approach is that my callback is being called on every
folder change and also on every item selection in an appointment folder.

Any suggestions on which approach is better? Thanks in advance.

- Manish
 
K

Ken Slovak - [MVP - Outlook]

Both of the events you mention are Item level events, best handled by
instantiating an Item and Inspector in the Inspectors.NewInspector() event
handler. You check the item type in that handler for
Inspector.CurrentItem.Class (use reflection for that) and if it's an
appointment or meeting item (whatever you want to handle) instantiate your
Item and Inspector objects.

Most of us use lists of Inspector wrapper classes to handle multiple open
items. In the wrapper class you instantiate the item event handlers you
want. That's a much more isolated approach, each item in its own Inspector
wrapper class and it keeps all the items in scope.
 
M

Manish

Hi Ken,

Thanks for the response. I am using your suggested approach of having a
list of inspector wrappers. I used the TraveAgency sample from MSDN to
structure the code of my add-in. Although I do register for the events on
the outlook item in the inspector class, thats not good enough because the
user can modify the start-time, end-time, subject using the explorer view by
dragging and dropping the appointment or deleting it. I need to be notified
when this happens. So doing it at the inspector wrapper level is not
sufficient. Which is why I have to either register events for all of my
add-in's managed calender appointments or I have to register the events
during item selection.
Is my approach correct?
 
K

Ken Slovak - [MVP - Outlook]

In that case registering for events you want for all items in the Selection
collection would be the way to go to handle changes from in-cell editing.
 
M

Manish

Thank you.

Ken Slovak - said:
In that case registering for events you want for all items in the Selection
collection would be the way to go to handle changes from in-cell editing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top