Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Add-ins for Outlook (http://www.outlookbanter.com/add-ins-outlook/)
-   -   Outlook 2003 Appointments -- drag and drop event using C# (http://www.outlookbanter.com/add-ins-outlook/75957-outlook-2003-appointments-drag-drop.html)

Curtis Justus July 28th 08 10:24 PM

Outlook 2003 Appointments -- drag and drop event using C#
 
Hi everybody,

I have created an add-in where I need to capture a drag and drop event of an
appointment in a user's calendar. I used the ItemLoad event in the 2007
libraries, but that doesn't exist in 2003.

I have attached to the Items.ItemChange event of the calendar folder
(olFolderCalendar), but that never fires. For that matter, neither does the
ItemAdd or ItemRemove events.

I have my inspectors hooked up, but they never fire because an inspector is
not created on a drag-drop of an appointment.

Would anybody have any ideas of something I can try?

Thanks for your help,
cj


Ken Slovak - [MVP - Outlook] July 29th 08 01:47 PM

Outlook 2003 Appointments -- drag and drop event using C#
 
If you add a new item to the calendar folder, not with drag and drop but
Actions, New Appointment does ItemAdd() fire at all? If not then it's
something in how you're creating or scoping your event handler.

Is the folder object and items collection declared at a class or other scope
level that will keep them alive once your procedure where you add the event
handler ends?

Show the code you use to create the event handlers.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Curtis Justus" wrote in message
...
Hi everybody,

I have created an add-in where I need to capture a drag and drop event of
an appointment in a user's calendar. I used the ItemLoad event in the
2007 libraries, but that doesn't exist in 2003.

I have attached to the Items.ItemChange event of the calendar folder
(olFolderCalendar), but that never fires. For that matter, neither does
the ItemAdd or ItemRemove events.

I have my inspectors hooked up, but they never fire because an inspector
is not created on a drag-drop of an appointment.

Would anybody have any ideas of something I can try?

Thanks for your help,
cj



Curtis Justus July 29th 08 02:04 PM

Outlook 2003 Appointments -- drag and drop event using C#
 
Hello Ken,

If I hook up the ItemAdd event, it does not fire if I add anything -- even
without the drag and drop.

Here is the code I am using...

public partial class ThisAddIn
{
private Outlook.Application outApp;
private Outlook.NameSpace _nameSpace;
private Outlook.MAPIFolder _calendarFolder;

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
outApp = this.Application;

_nameSpace = outApp.GetNamespace("MAPI");

_calendarFolder =
_nameSpace.GetDefaultFolder(OlDefaultFolders.olFol derCalendar);

_calendarFolder.Items.ItemAdd += new
ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
}

void Items_ItemAdd(object Item)
{
MessageBox.Show("Item Added");
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
_calendarFolder.Items.ItemAdd -= new
ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
outApp = null;

}
}

Thanks for your help...
cj

"Ken Slovak - [MVP - Outlook]" wrote in message
...
If you add a new item to the calendar folder, not with drag and drop but
Actions, New Appointment does ItemAdd() fire at all? If not then it's
something in how you're creating or scoping your event handler.

Is the folder object and items collection declared at a class or other
scope level that will keep them alive once your procedure where you add
the event handler ends?

Show the code you use to create the event handlers.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Curtis Justus" wrote in message
...
Hi everybody,

I have created an add-in where I need to capture a drag and drop event of
an appointment in a user's calendar. I used the ItemLoad event in the
2007 libraries, but that doesn't exist in 2003.

I have attached to the Items.ItemChange event of the calendar folder
(olFolderCalendar), but that never fires. For that matter, neither does
the ItemAdd or ItemRemove events.

I have my inspectors hooked up, but they never fire because an inspector
is not created on a drag-drop of an appointment.

Would anybody have any ideas of something I can try?

Thanks for your help,
cj




Ken Slovak - [MVP - Outlook] July 29th 08 02:15 PM

Outlook 2003 Appointments -- drag and drop event using C#
 
Your Items collection is going out of scope as soon as that procedure ends.
Then it gets garbage collected and your event handlers then fail to fire.

Your class level declarations section should include a declaration for an
Items collection:

private Outlook.Items _items;

Assign that to your calendar folder's items collection and add the event
handler to that Items collection and the events should start to fire.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Curtis Justus" wrote in message
...
Hello Ken,

If I hook up the ItemAdd event, it does not fire if I add anything -- even
without the drag and drop.

Here is the code I am using...

public partial class ThisAddIn
{
private Outlook.Application outApp;
private Outlook.NameSpace _nameSpace;
private Outlook.MAPIFolder _calendarFolder;

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
outApp = this.Application;

_nameSpace = outApp.GetNamespace("MAPI");

_calendarFolder =
_nameSpace.GetDefaultFolder(OlDefaultFolders.olFol derCalendar);

_calendarFolder.Items.ItemAdd += new
ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
}

void Items_ItemAdd(object Item)
{
MessageBox.Show("Item Added");
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
_calendarFolder.Items.ItemAdd -= new
ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
outApp = null;

}
}

Thanks for your help...
cj



Curtis Justus July 29th 08 02:20 PM

Outlook 2003 Appointments -- drag and drop event using C#
 
VOILA!

Ken... you got me thinking about the scope. Since I wasn't referring to the
Items collection directly in my definition, I thought maybe something was
getting disconnected in the Interop with the com layer. I set up a class
level variable:

private Items _calendarItems;

Then, I put the following code in the startup:

_calendarItems.ItemChange += new
ItemsEvents_ItemChangeEventHandler(_calendarItems_ ItemChange);

Lo and behold, the change event fires -- even on the drag and drop.

Thanks for pointing me in the right direction...
cj

"Curtis Justus" wrote in message
...
Hello Ken,

If I hook up the ItemAdd event, it does not fire if I add anything -- even
without the drag and drop.

Here is the code I am using...

public partial class ThisAddIn
{
private Outlook.Application outApp;
private Outlook.NameSpace _nameSpace;
private Outlook.MAPIFolder _calendarFolder;

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
outApp = this.Application;

_nameSpace = outApp.GetNamespace("MAPI");

_calendarFolder =
_nameSpace.GetDefaultFolder(OlDefaultFolders.olFol derCalendar);

_calendarFolder.Items.ItemAdd += new
ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
}

void Items_ItemAdd(object Item)
{
MessageBox.Show("Item Added");
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
_calendarFolder.Items.ItemAdd -= new
ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
outApp = null;

}
}

Thanks for your help...
cj

"Ken Slovak - [MVP - Outlook]" wrote in message
...
If you add a new item to the calendar folder, not with drag and drop but
Actions, New Appointment does ItemAdd() fire at all? If not then it's
something in how you're creating or scoping your event handler.

Is the folder object and items collection declared at a class or other
scope level that will keep them alive once your procedure where you add
the event handler ends?

Show the code you use to create the event handlers.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Curtis Justus" wrote in message
...
Hi everybody,

I have created an add-in where I need to capture a drag and drop event
of an appointment in a user's calendar. I used the ItemLoad event in
the 2007 libraries, but that doesn't exist in 2003.

I have attached to the Items.ItemChange event of the calendar folder
(olFolderCalendar), but that never fires. For that matter, neither does
the ItemAdd or ItemRemove events.

I have my inspectors hooked up, but they never fire because an inspector
is not created on a drag-drop of an appointment.

Would anybody have any ideas of something I can try?

Thanks for your help,
cj





Ken Slovak - [MVP - Outlook] July 29th 08 02:30 PM

Outlook 2003 Appointments -- drag and drop event using C#
 
You always have to be more aware of scoping and possible garbage collection
in managed code than in unmanaged code. You'd be surprised at how many
problems are solved just by thinking about and following scoping rules.

Good, I'm glad things are working now.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Curtis Justus" wrote in message
...
VOILA!

Ken... you got me thinking about the scope. Since I wasn't referring to
the Items collection directly in my definition, I thought maybe something
was getting disconnected in the Interop with the com layer. I set up a
class level variable:

private Items _calendarItems;

Then, I put the following code in the startup:

_calendarItems.ItemChange += new
ItemsEvents_ItemChangeEventHandler(_calendarItems_ ItemChange);

Lo and behold, the change event fires -- even on the drag and drop.

Thanks for pointing me in the right direction...
cj




All times are GMT +1. The time now is 12:35 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com