Mail item Forward event fails first time

R

Ron Coffee

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;
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.
 
K

Ken Slovak - [MVP - Outlook]

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

Ron Coffee

You were right on! When the toolbar construtor was call the item wen out of
scope.

Ken Slovak - said:
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.




Ron Coffee said:
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;
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.

 

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