MapiFolder Items ItemChange is not firing

A

AtulSureka

Hi,

I have used the following code to Handle the EditItem Event of Task Items

using System;
using System.Data;
using System.Collections;
using Outlook = Microsoft.Office.Interop.Outlook;

public class MyClass
{
private static Outlook.NameSpace nSpace;
private static Outlook.MAPIFolder mapiFolder;

public static void Main(string[] args)
{
Outlook.Application app = new
Microsoft.Office.Interop.Outlook.Application();
nSpace = app.GetNamespace("MAPI");

mapiFolder =
nSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
mapiFolder.Items.ItemChange += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemChangeEventHandler(TaskItemChanged);

Console.ReadLine();
}

private static void TaskItemChanged(object Item)
{
Console.WriteLine("Item Has been chnaged");
}
}

However many times ItemChange event does not fire.
What can be the possible reasons?
Is there any work around for it?

- Atul Sureka
 
T

Thaddaeus Parker

One way I found to get around this is to have the Explorer.SelectionChange
event add the Items_Change event for the folder. The problem with the
selection change event is that it gets fired each and every time you gain
focus on a separate view,folder, item, etc. Here is the sample code that I
used.

static int itemChangeEventCount = 0;

private void currentExplorer_SelectionChange()

{

if(string.Compare(currentExplorer.CurrentFolder.Name,taskItemsFolderCollection.Name,
true) == 0)

{

//we are tracking changes to the taskItemsFolderCollection

Trace.WriteLine("We had a selection change");

Trace.WriteLine("we are tracking any changes to the task Items");

if(itemChangeEventCount < 1)

{

taskItemsFolderCollection.Items.ItemChange += new
ItemsEvents_ItemChangeEventHandler(Items_ItemChange);

itemChangeEventCount++;

}}}
if you don't make a check to see whether or not you are in the right folder
during the selection change you end up with A LOT of events firing when they
shouldn't.

Regards,

Thaddaeus.
 

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