View Single Post
  #1  
Old July 31st 07, 08:40 AM posted to microsoft.public.outlook.program_addins
Luk[_2_]
external usenet poster
 
Posts: 5
Default Items ItemAdd Outlook 2007 problem

I wan't to have something like this:

I add items to Items collection and I do not wan't to handle the event (at
startup) and after I add some of those items I wan't to start handling the
ItemAdd event.

My code looks like this:

class Folder
{
private Outlook.Folder _folder = null;

private Outlook.Items _items = null;

private Logic.ContactsLogic _contactsLogic = null;

public Folder(Outlook.NameSpace outlook, string folderName)
{
Outlook.Folder defaultCalendarFolder =
(Outlook.Folder)outlook.GetDefaultFolder(Outlook.O lDefaultFolders.olFolderContacts);

_folder = GetFolder(defaultCalendarFolder, folderName);

_items = _folder.Items;

_contactsLogic = new ContactsLogic();

// In here I add some items to the folder
_contactsLogic.SynchronizeContacts(this);

HookUpEvents();
}


private void HookUpEvents()
{
_folder.BeforeFolderMove += new
Microsoft.Office.Interop.Outlook.MAPIFolderEvents_ 12_BeforeFolderMoveEventHandler(Folder_BeforeFolde rMove);
_folder.BeforeItemMove += new
Microsoft.Office.Interop.Outlook.MAPIFolderEvents_ 12_BeforeItemMoveEventHandler(Folder_BeforeItemMov e);
_items.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA ddEventHandler(Items_ItemAdd);
_items.ItemChange += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC hangeEventHandler(Items_ItemChange);

_eventsHookedUp = true;
}
}

Although I add event handlers after I add the Items to the collection (in
statement _contactsLogic.SynchronizeContacts(this); ) I still get to handle
them in Items_ItemAdd and I don't wan't to
Ads