![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Dear reader,
I've created an add-in for Outlook 2007; this add-in sets the color of the appointments related to the location. - In the OnStartupComplete() event all appointments will be colored. - In the Outlook.MAPIFolder.AddItem event new appointmets will be colored. But, it goes wrong with the Outlook.MAPIFolder.ChangeItem event... //_calendarItems is of type Outlook.MAPIFolder _calendarItems.ItemChange += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC hangeEventHandler(Items_ItemChange); //ItemChange event handler void Items_ItemChange(object Item) { Outlook.AppointmentItem appointment = (Outlook.AppointmentItem)Item; SetColorAppointment(appointment); } //changes color appointment (called within all events mentioned above) private void SetColorAppointment(Outlook.AppointmentItem appointment) { int color = GetLocationColor(appointment.Location); appointment.PropertyAccessor.SetProperty"http://schemas.microsoft.com/mapi/id/ {00062002-0000-0000-C000-000000000046}/82140003", color); appointment.Save(); } When the SetColorAppointment() has been called; the event Item_ItemChange() will be called again and again and again, because the item changed off course! How can this behavour be solved? I also tried this version of the SetColorAppointment() method (with Redemption); the Items_ItemChange() will also be called again and again... Rdo.SafeAppointmentItem safeAppointment = new Rdo.SafeAppointmentItem(); safeAppointment.Item = appointment; int propertyID = safeAppointment.GetIDsFromNames("{00062002-0000-0000-C000-000000000046}", 0x8214); propertyID = propertyID | 0x3; safeAppointment.set_Fields(propertyID, color); //appointment.Subject = appointment.Subject; appointment.Save(); I also tried using the Outlook.AppointmentItem.PropertyChange event. This event fires when the Location property has been changed but when I handle this event and try to set the colors of all appointments; the appointment wherefrom I just changed the location still has the old location??? I checked it and the case is that the I continuously change the color of the previous location! During this event it seems like I don't have the current MAPIFolder with the current appointment items? void appointment_PropertyChange(string Name) { if ( Name == "Location" ) { foreach (Outlook.AppointmentItem appointment in _items) { SetColorAppointment(appointment); } } } In Outlook 2003 I got it working with the Redemption method and PropertyChange event, but this approach does not seem to work in Outlook 2007... What is the best solution to catch the event that the location has been changed of an appoinment and changing the color successfully in Outlook 2007? Thank you in advance, Johan Machielse |
Ads |
#2
|
|||
|
|||
![]()
Setting a property of an item in ItemChange() will of course cause that
event to fire again. So you need to put a flag on the item as you change the color to show it was already changed. An alternative would be to maintain a list of items that have been changed in that event handler and if the item is already in the list then don't change it again. -- 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 "Johan Machielse" wrote in message ... Dear reader, I've created an add-in for Outlook 2007; this add-in sets the color of the appointments related to the location. - In the OnStartupComplete() event all appointments will be colored. - In the Outlook.MAPIFolder.AddItem event new appointmets will be colored. But, it goes wrong with the Outlook.MAPIFolder.ChangeItem event... //_calendarItems is of type Outlook.MAPIFolder _calendarItems.ItemChange += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC hangeEventHandler(Items_ItemChange); //ItemChange event handler void Items_ItemChange(object Item) { Outlook.AppointmentItem appointment = (Outlook.AppointmentItem)Item; SetColorAppointment(appointment); } //changes color appointment (called within all events mentioned above) private void SetColorAppointment(Outlook.AppointmentItem appointment) { int color = GetLocationColor(appointment.Location); appointment.PropertyAccessor.SetProperty"http://schemas.microsoft.com/mapi/id/ {00062002-0000-0000-C000-000000000046}/82140003", color); appointment.Save(); } When the SetColorAppointment() has been called; the event Item_ItemChange() will be called again and again and again, because the item changed off course! How can this behavour be solved? I also tried this version of the SetColorAppointment() method (with Redemption); the Items_ItemChange() will also be called again and again... Rdo.SafeAppointmentItem safeAppointment = new Rdo.SafeAppointmentItem(); safeAppointment.Item = appointment; int propertyID = safeAppointment.GetIDsFromNames("{00062002-0000-0000-C000-000000000046}", 0x8214); propertyID = propertyID | 0x3; safeAppointment.set_Fields(propertyID, color); //appointment.Subject = appointment.Subject; appointment.Save(); I also tried using the Outlook.AppointmentItem.PropertyChange event. This event fires when the Location property has been changed but when I handle this event and try to set the colors of all appointments; the appointment wherefrom I just changed the location still has the old location??? I checked it and the case is that the I continuously change the color of the previous location! During this event it seems like I don't have the current MAPIFolder with the current appointment items? void appointment_PropertyChange(string Name) { if ( Name == "Location" ) { foreach (Outlook.AppointmentItem appointment in _items) { SetColorAppointment(appointment); } } } In Outlook 2003 I got it working with the Redemption method and PropertyChange event, but this approach does not seem to work in Outlook 2007... What is the best solution to catch the event that the location has been changed of an appoinment and changing the color successfully in Outlook 2007? Thank you in advance, Johan Machielse |
#3
|
|||
|
|||
![]()
Yep, I ready figured it out! I used a flag to check if the appointment was
already changed! Thank you Ken! Johan "Ken Slovak - [MVP - Outlook]" wrote: Setting a property of an item in ItemChange() will of course cause that event to fire again. So you need to put a flag on the item as you change the color to show it was already changed. An alternative would be to maintain a list of items that have been changed in that event handler and if the item is already in the list then don't change it again. -- 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 "Johan Machielse" wrote in message ... Dear reader, I've created an add-in for Outlook 2007; this add-in sets the color of the appointments related to the location. - In the OnStartupComplete() event all appointments will be colored. - In the Outlook.MAPIFolder.AddItem event new appointmets will be colored. But, it goes wrong with the Outlook.MAPIFolder.ChangeItem event... //_calendarItems is of type Outlook.MAPIFolder _calendarItems.ItemChange += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC hangeEventHandler(Items_ItemChange); //ItemChange event handler void Items_ItemChange(object Item) { Outlook.AppointmentItem appointment = (Outlook.AppointmentItem)Item; SetColorAppointment(appointment); } //changes color appointment (called within all events mentioned above) private void SetColorAppointment(Outlook.AppointmentItem appointment) { int color = GetLocationColor(appointment.Location); appointment.PropertyAccessor.SetProperty"http://schemas.microsoft.com/mapi/id/ {00062002-0000-0000-C000-000000000046}/82140003", color); appointment.Save(); } When the SetColorAppointment() has been called; the event Item_ItemChange() will be called again and again and again, because the item changed off course! How can this behavour be solved? I also tried this version of the SetColorAppointment() method (with Redemption); the Items_ItemChange() will also be called again and again... Rdo.SafeAppointmentItem safeAppointment = new Rdo.SafeAppointmentItem(); safeAppointment.Item = appointment; int propertyID = safeAppointment.GetIDsFromNames("{00062002-0000-0000-C000-000000000046}", 0x8214); propertyID = propertyID | 0x3; safeAppointment.set_Fields(propertyID, color); //appointment.Subject = appointment.Subject; appointment.Save(); I also tried using the Outlook.AppointmentItem.PropertyChange event. This event fires when the Location property has been changed but when I handle this event and try to set the colors of all appointments; the appointment wherefrom I just changed the location still has the old location??? I checked it and the case is that the I continuously change the color of the previous location! During this event it seems like I don't have the current MAPIFolder with the current appointment items? void appointment_PropertyChange(string Name) { if ( Name == "Location" ) { foreach (Outlook.AppointmentItem appointment in _items) { SetColorAppointment(appointment); } } } In Outlook 2003 I got it working with the Redemption method and PropertyChange event, but this approach does not seem to work in Outlook 2007... What is the best solution to catch the event that the location has been changed of an appoinment and changing the color successfully in Outlook 2007? Thank you in advance, Johan Machielse |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How do I lock an appointment so it can not be changed? | mjs | Outlook - Calandaring | 12 | June 25th 08 05:14 PM |
why appointment.LastModificationTime isn't changed? | Cynthia | Add-ins for Outlook | 3 | December 27th 07 06:42 PM |
an event or appointment in the calendar in outlook 2007 does not w | izzy | Outlook - Calandaring | 3 | June 21st 07 01:47 AM |
itemchange event in public (exchange) folder occurs if nothing is changed | MIchael | Outlook and VBA | 7 | May 23rd 07 11:04 PM |
Changes to Contact Item are not displayed if changed in New_Inspector-Event | cs | Add-ins for Outlook | 1 | December 8th 06 06:40 PM |