Mail item Forward event fails first time

Home » Outlook addins and plugins development » Developer Outlook add-ins
Mail item Forward event fails first time [message #300069] Mon, 12 May 2008 17:23 Go to next message
Ron Coffee  is currently offline Ron Coffee
Messages: 12
Registered: May 2008
Junior Member
I have a COM add in using VSTO 2005 for outlook 2003. My code adds a Forward
event handler using the explorer selection change event.
void _explr_SelectionChange()
{
for (int i = 1; i <= _explr.Selection.Count; i++)
{
object selectedItem = _explr.Selection[i];
if (selectedItem is MailItem)
{
MailItem _item = (MailItem)selectedItem;
((ItemEvents_10_Event)_item).Forward += _item_Forward;
}
}
}

The event does not fire the first time I forward an item. It fires normally
after the first time.

There is no exception being raised. I should add that we add a tool bart to
to the outlook item. It seems like the constructor for the tool bar
interferes with the Forward event registration.
Re: Mail item Forward event fails first time [message #300247] Tue, 13 May 2008 09:08 Go to previous messageGo to next message
kenslovak  is currently offline kenslovak
Messages: 7232
Registered: May 2006
Senior Member
I have no idea what your toolbar construction code looks like but your
forward code would correctly handle only 1 selected item, and the
declarations for the event handlers are local objects that will go out of
scope the second the SelectionChange event procedure ends.

You should be using a list or collection of some kind to add your selected
items and the event handlers for them to keep the item objects and their
event handlers in scope.

--
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


"Ron Coffee" <Ron Coffee@discussions.microsoft.com> wrote in message
news:5A03DAD9-69B5-4FA1-9050-D28183299FA6@microsoft.com...
>I have a COM add in using VSTO 2005 for outlook 2003. My code adds a
>Forward
> event handler using the explorer selection change event.
> void _explr_SelectionChange()
> {
> for (int i = 1; i <= _explr.Selection.Count; i++)
> {
> object selectedItem = _explr.Selection[i];
> if (selectedItem is MailItem)
> {
> MailItem _item = (MailItem)selectedItem;
> ((ItemEvents_10_Event)_item).Forward += _item_Forward;
> }
> }
> }
>
> The event does not fire the first time I forward an item. It fires
> normally
> after the first time.
>
> There is no exception being raised. I should add that we add a tool bart
> to
> to the outlook item. It seems like the constructor for the tool bar
> interferes with the Forward event registration.



Re: Mail item Forward event fails first time [message #300293] Tue, 13 May 2008 11:21 Go to previous message
Ron Coffee  is currently offline Ron Coffee
Messages: 12
Registered: May 2008
Junior Member
You were right on! When the toolbar construtor was call the item wen out of
scope.

"Ken Slovak - [MVP - Outlook]" wrote:

> I have no idea what your toolbar construction code looks like but your
> forward code would correctly handle only 1 selected item, and the
> declarations for the event handlers are local objects that will go out of
> scope the second the SelectionChange event procedure ends.
>
> You should be using a list or collection of some kind to add your selected
> items and the event handlers for them to keep the item objects and their
> event handlers in scope.
>
> --
> 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
>
>
> "Ron Coffee" <Ron Coffee@discussions.microsoft.com> wrote in message
> news:5A03DAD9-69B5-4FA1-9050-D28183299FA6@microsoft.com...
> >I have a COM add in using VSTO 2005 for outlook 2003. My code adds a
> >Forward
> > event handler using the explorer selection change event.
> > void _explr_SelectionChange()
> > {
> > for (int i = 1; i <= _explr.Selection.Count; i++)
> > {
> > object selectedItem = _explr.Selection[i];
> > if (selectedItem is MailItem)
> > {
> > MailItem _item = (MailItem)selectedItem;
> > ((ItemEvents_10_Event)_item).Forward += _item_Forward;
> > }
> > }
> > }
> >
> > The event does not fire the first time I forward an item. It fires
> > normally
> > after the first time.
> >
> > There is no exception being raised. I should add that we add a tool bart
> > to
> > to the outlook item. It seems like the constructor for the tool bar
> > interferes with the Forward event registration.
>
>
Re: Mail item Forward event fails first time [message #302113] Tue, 13 May 2008 09:08 Go to previous message
kenslovak  is currently offline kenslovak
Messages: 7232
Registered: May 2006
Senior Member
I have no idea what your toolbar construction code looks like but your
forward code would correctly handle only 1 selected item, and the
declarations for the event handlers are local objects that will go out of
scope the second the SelectionChange event procedure ends.

You should be using a list or collection of some kind to add your selected
items and the event handlers for them to keep the item objects and their
event handlers in scope.

--
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


"Ron Coffee" <Ron Coffee@discussions.microsoft.com> wrote in message
news:5A03DAD9-69B5-4FA1-9050-D28183299FA6@microsoft.com...
>I have a COM add in using VSTO 2005 for outlook 2003. My code adds a
>Forward
> event handler using the explorer selection change event.
> void _explr_SelectionChange()
> {
> for (int i = 1; i <= _explr.Selection.Count; i++)
> {
> object selectedItem = _explr.Selection[i];
> if (selectedItem is MailItem)
> {
> MailItem _item = (MailItem)selectedItem;
> ((ItemEvents_10_Event)_item).Forward += _item_Forward;
> }
> }
> }
>
> The event does not fire the first time I forward an item. It fires
> normally
> after the first time.
>
> There is no exception being raised. I should add that we add a tool bart
> to
> to the outlook item. It seems like the constructor for the tool bar
> interferes with the Forward event registration.
Re: Mail item Forward event fails first time [message #302115] Tue, 13 May 2008 11:21 Go to previous message
Ron Coffee  is currently offline Ron Coffee
Messages: 12
Registered: May 2008
Junior Member
You were right on! When the toolbar construtor was call the item wen out of
scope.

"Ken Slovak - [MVP - Outlook]" wrote:

> I have no idea what your toolbar construction code looks like but your
> forward code would correctly handle only 1 selected item, and the
> declarations for the event handlers are local objects that will go out of
> scope the second the SelectionChange event procedure ends.
>
> You should be using a list or collection of some kind to add your selected
> items and the event handlers for them to keep the item objects and their
> event handlers in scope.
>
> --
> 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
>
>
> "Ron Coffee" <Ron Coffee@discussions.microsoft.com> wrote in message
> news:5A03DAD9-69B5-4FA1-9050-D28183299FA6@microsoft.com...
> >I have a COM add in using VSTO 2005 for outlook 2003. My code adds a
> >Forward
> > event handler using the explorer selection change event.
> > void _explr_SelectionChange()
> > {
> > for (int i = 1; i <= _explr.Selection.Count; i++)
> > {
> > object selectedItem = _explr.Selection[i];
> > if (selectedItem is MailItem)
> > {
> > MailItem _item = (MailItem)selectedItem;
> > ((ItemEvents_10_Event)_item).Forward += _item_Forward;
> > }
> > }
> > }
> >
> > The event does not fire the first time I forward an item. It fires
> > normally
> > after the first time.
> >
> > There is no exception being raised. I should add that we add a tool bart
> > to
> > to the outlook item. It seems like the constructor for the tool bar
> > interferes with the Forward event registration.
>
>
Re: Mail item Forward event fails first time [message #302612] Tue, 13 May 2008 09:08 Go to previous message
kenslovak  is currently offline kenslovak
Messages: 7232
Registered: May 2006
Senior Member
I have no idea what your toolbar construction code looks like but your
forward code would correctly handle only 1 selected item, and the
declarations for the event handlers are local objects that will go out of
scope the second the SelectionChange event procedure ends.

You should be using a list or collection of some kind to add your selected
items and the event handlers for them to keep the item objects and their
event handlers in scope.

--
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


"Ron Coffee" <Ron Coffee@discussions.microsoft.com> wrote in message
news:5A03DAD9-69B5-4FA1-9050-D28183299FA6@microsoft.com...
>I have a COM add in using VSTO 2005 for outlook 2003. My code adds a
>Forward
> event handler using the explorer selection change event.
> void _explr_SelectionChange()
> {
> for (int i = 1; i <= _explr.Selection.Count; i++)
> {
> object selectedItem = _explr.Selection[i];
> if (selectedItem is MailItem)
> {
> MailItem _item = (MailItem)selectedItem;
> ((ItemEvents_10_Event)_item).Forward += _item_Forward;
> }
> }
> }
>
> The event does not fire the first time I forward an item. It fires
> normally
> after the first time.
>
> There is no exception being raised. I should add that we add a tool bart
> to
> to the outlook item. It seems like the constructor for the tool bar
> interferes with the Forward event registration.
Re: Mail item Forward event fails first time [message #302614] Tue, 13 May 2008 11:21 Go to previous message
Ron Coffee  is currently offline Ron Coffee
Messages: 12
Registered: May 2008
Junior Member
You were right on! When the toolbar construtor was call the item wen out of
scope.

"Ken Slovak - [MVP - Outlook]" wrote:

> I have no idea what your toolbar construction code looks like but your
> forward code would correctly handle only 1 selected item, and the
> declarations for the event handlers are local objects that will go out of
> scope the second the SelectionChange event procedure ends.
>
> You should be using a list or collection of some kind to add your selected
> items and the event handlers for them to keep the item objects and their
> event handlers in scope.
>
> --
> 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
>
>
> "Ron Coffee" <Ron Coffee@discussions.microsoft.com> wrote in message
> news:5A03DAD9-69B5-4FA1-9050-D28183299FA6@microsoft.com...
> >I have a COM add in using VSTO 2005 for outlook 2003. My code adds a
> >Forward
> > event handler using the explorer selection change event.
> > void _explr_SelectionChange()
> > {
> > for (int i = 1; i <= _explr.Selection.Count; i++)
> > {
> > object selectedItem = _explr.Selection[i];
> > if (selectedItem is MailItem)
> > {
> > MailItem _item = (MailItem)selectedItem;
> > ((ItemEvents_10_Event)_item).Forward += _item_Forward;
> > }
> > }
> > }
> >
> > The event does not fire the first time I forward an item. It fires
> > normally
> > after the first time.
> >
> > There is no exception being raised. I should add that we add a tool bart
> > to
> > to the outlook item. It seems like the constructor for the tool bar
> > interferes with the Forward event registration.
>
>
Re: Mail item Forward event fails first time [message #303110] Tue, 13 May 2008 09:08 Go to previous message
kenslovak  is currently offline kenslovak
Messages: 7232
Registered: May 2006
Senior Member
I have no idea what your toolbar construction code looks like but your
forward code would correctly handle only 1 selected item, and the
declarations for the event handlers are local objects that will go out of
scope the second the SelectionChange event procedure ends.

You should be using a list or collection of some kind to add your selected
items and the event handlers for them to keep the item objects and their
event handlers in scope.

--
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


"Ron Coffee" <Ron Coffee@discussions.microsoft.com> wrote in message
news:5A03DAD9-69B5-4FA1-9050-D28183299FA6@microsoft.com...
>I have a COM add in using VSTO 2005 for outlook 2003. My code adds a
>Forward
> event handler using the explorer selection change event.
> void _explr_SelectionChange()
> {
> for (int i = 1; i <= _explr.Selection.Count; i++)
> {
> object selectedItem = _explr.Selection[i];
> if (selectedItem is MailItem)
> {
> MailItem _item = (MailItem)selectedItem;
> ((ItemEvents_10_Event)_item).Forward += _item_Forward;
> }
> }
> }
>
> The event does not fire the first time I forward an item. It fires
> normally
> after the first time.
>
> There is no exception being raised. I should add that we add a tool bart
> to
> to the outlook item. It seems like the constructor for the tool bar
> interferes with the Forward event registration.
Re: Mail item Forward event fails first time [message #303112] Tue, 13 May 2008 11:21 Go to previous message
Ron Coffee  is currently offline Ron Coffee
Messages: 12
Registered: May 2008
Junior Member
You were right on! When the toolbar construtor was call the item wen out of
scope.

"Ken Slovak - [MVP - Outlook]" wrote:

> I have no idea what your toolbar construction code looks like but your
> forward code would correctly handle only 1 selected item, and the
> declarations for the event handlers are local objects that will go out of
> scope the second the SelectionChange event procedure ends.
>
> You should be using a list or collection of some kind to add your selected
> items and the event handlers for them to keep the item objects and their
> event handlers in scope.
>
> --
> 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
>
>
> "Ron Coffee" <Ron Coffee@discussions.microsoft.com> wrote in message
> news:5A03DAD9-69B5-4FA1-9050-D28183299FA6@microsoft.com...
> >I have a COM add in using VSTO 2005 for outlook 2003. My code adds a
> >Forward
> > event handler using the explorer selection change event.
> > void _explr_SelectionChange()
> > {
> > for (int i = 1; i <= _explr.Selection.Count; i++)
> > {
> > object selectedItem = _explr.Selection[i];
> > if (selectedItem is MailItem)
> > {
> > MailItem _item = (MailItem)selectedItem;
> > ((ItemEvents_10_Event)_item).Forward += _item_Forward;
> > }
> > }
> > }
> >
> > The event does not fire the first time I forward an item. It fires
> > normally
> > after the first time.
> >
> > There is no exception being raised. I should add that we add a tool bart
> > to
> > to the outlook item. It seems like the constructor for the tool bar
> > interferes with the Forward event registration.
>
>
Re: Mail item Forward event fails first time [message #303590] Tue, 13 May 2008 09:08 Go to previous message
kenslovak  is currently offline kenslovak
Messages: 7232
Registered: May 2006
Senior Member
I have no idea what your toolbar construction code looks like but your
forward code would correctly handle only 1 selected item, and the
declarations for the event handlers are local objects that will go out of
scope the second the SelectionChange event procedure ends.

You should be using a list or collection of some kind to add your selected
items and the event handlers for them to keep the item objects and their
event handlers in scope.

--
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


"Ron Coffee" <Ron Coffee@discussions.microsoft.com> wrote in message
news:5A03DAD9-69B5-4FA1-9050-D28183299FA6@microsoft.com...
>I have a COM add in using VSTO 2005 for outlook 2003. My code adds a
>Forward
> event handler using the explorer selection change event.
> void _explr_SelectionChange()
> {
> for (int i = 1; i <= _explr.Selection.Count; i++)
> {
> object selectedItem = _explr.Selection[i];
> if (selectedItem is MailItem)
> {
> MailItem _item = (MailItem)selectedItem;
> ((ItemEvents_10_Event)_item).Forward += _item_Forward;
> }
> }
> }
>
> The event does not fire the first time I forward an item. It fires
> normally
> after the first time.
>
> There is no exception being raised. I should add that we add a tool bart
> to
> to the outlook item. It seems like the constructor for the tool bar
> interferes with the Forward event registration.
Re: Mail item Forward event fails first time [message #303592] Tue, 13 May 2008 11:21 Go to previous message
Ron Coffee  is currently offline Ron Coffee
Messages: 12
Registered: May 2008
Junior Member
You were right on! When the toolbar construtor was call the item wen out of
scope.

"Ken Slovak - [MVP - Outlook]" wrote:

> I have no idea what your toolbar construction code looks like but your
> forward code would correctly handle only 1 selected item, and the
> declarations for the event handlers are local objects that will go out of
> scope the second the SelectionChange event procedure ends.
>
> You should be using a list or collection of some kind to add your selected
> items and the event handlers for them to keep the item objects and their
> event handlers in scope.
>
> --
> 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
>
>
> "Ron Coffee" <Ron Coffee@discussions.microsoft.com> wrote in message
> news:5A03DAD9-69B5-4FA1-9050-D28183299FA6@microsoft.com...
> >I have a COM add in using VSTO 2005 for outlook 2003. My code adds a
> >Forward
> > event handler using the explorer selection change event.
> > void _explr_SelectionChange()
> > {
> > for (int i = 1; i <= _explr.Selection.Count; i++)
> > {
> > object selectedItem = _explr.Selection[i];
> > if (selectedItem is MailItem)
> > {
> > MailItem _item = (MailItem)selectedItem;
> > ((ItemEvents_10_Event)_item).Forward += _item_Forward;
> > }
> > }
> > }
> >
> > The event does not fire the first time I forward an item. It fires
> > normally
> > after the first time.
> >
> > There is no exception being raised. I should add that we add a tool bart
> > to
> > to the outlook item. It seems like the constructor for the tool bar
> > interferes with the Forward event registration.
>
>
Re: Mail item Forward event fails first time [message #304123] Tue, 13 May 2008 09:08 Go to previous message
kenslovak  is currently offline kenslovak
Messages: 7232
Registered: May 2006
Senior Member
I have no idea what your toolbar construction code looks like but your
forward code would correctly handle only 1 selected item, and the
declarations for the event handlers are local objects that will go out of
scope the second the SelectionChange event procedure ends.

You should be using a list or collection of some kind to add your selected
items and the event handlers for them to keep the item objects and their
event handlers in scope.

--
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


"Ron Coffee" <Ron Coffee@discussions.microsoft.com> wrote in message
news:5A03DAD9-69B5-4FA1-9050-D28183299FA6@microsoft.com...
>I have a COM add in using VSTO 2005 for outlook 2003. My code adds a
>Forward
> event handler using the explorer selection change event.
> void _explr_SelectionChange()
> {
> for (int i = 1; i <= _explr.Selection.Count; i++)
> {
> object selectedItem = _explr.Selection[i];
> if (selectedItem is MailItem)
> {
> MailItem _item = (MailItem)selectedItem;
> ((ItemEvents_10_Event)_item).Forward += _item_Forward;
> }
> }
> }
>
> The event does not fire the first time I forward an item. It fires
> normally
> after the first time.
>
> There is no exception being raised. I should add that we add a tool bart
> to
> to the outlook item. It seems like the constructor for the tool bar
> interferes with the Forward event registration.
Re: Mail item Forward event fails first time [message #304125] Tue, 13 May 2008 11:21 Go to previous message
Ron Coffee  is currently offline Ron Coffee
Messages: 12
Registered: May 2008
Junior Member
You were right on! When the toolbar construtor was call the item wen out of
scope.

"Ken Slovak - [MVP - Outlook]" wrote:

> I have no idea what your toolbar construction code looks like but your
> forward code would correctly handle only 1 selected item, and the
> declarations for the event handlers are local objects that will go out of
> scope the second the SelectionChange event procedure ends.
>
> You should be using a list or collection of some kind to add your selected
> items and the event handlers for them to keep the item objects and their
> event handlers in scope.
>
> --
> 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
>
>
> "Ron Coffee" <Ron Coffee@discussions.microsoft.com> wrote in message
> news:5A03DAD9-69B5-4FA1-9050-D28183299FA6@microsoft.com...
> >I have a COM add in using VSTO 2005 for outlook 2003. My code adds a
> >Forward
> > event handler using the explorer selection change event.
> > void _explr_SelectionChange()
> > {
> > for (int i = 1; i <= _explr.Selection.Count; i++)
> > {
> > object selectedItem = _explr.Selection[i];
> > if (selectedItem is MailItem)
> > {
> > MailItem _item = (MailItem)selectedItem;
> > ((ItemEvents_10_Event)_item).Forward += _item_Forward;
> > }
> > }
> > }
> >
> > The event does not fire the first time I forward an item. It fires
> > normally
> > after the first time.
> >
> > There is no exception being raised. I should add that we add a tool bart
> > to
> > to the outlook item. It seems like the constructor for the tool bar
> > interferes with the Forward event registration.
>
>
Previous Topic:Adding button to reading pane in outlook 2003 using shared addins
Next Topic:How is a row height set?
Goto Forum:
  


 
   
  
 
Top Outlook add-ins
Duplicate Email RemoverDuplicate Email Remover

Delete duplicate emails and posts in Outlook and Microsoft Exchange folders.

Duplicates Remover for OutlookDuplicates Remover for Outlook

Delete duplicates in Microsoft Outlook and Microsoft Exchange Server folders.

Genius Connect - MailGenius Connect - Mail

Store Outlook or Exchange mail in any SQL Database.

PlainSight Desktop CalendarPlainSight Desktop Calendar

Pretty desktop calendar integrates wallpaper, weather forecasts, Outlook.

Total 162 add-ins for Outlook
in 11 categories.

Latest news
  

© 2006-2008 Office Assistance LLC