Selection Object of Outlook View Control

T

tanutatu

Hi

We are using Outlook 2003 and above, VSTO and C# for developing an
Outlook add-in.

We are using the Outlook View Control to display messages from folders.

We wanted to process the items selected from outlook view control.For
the same we capture the "Selection_Change" event of the view control
and tried to access the "Selection" object in the event handler.

We did reach the event handler but we are not able get anything from
the "Selection" object.
i.e viewcontrol.Selection object has no appropriate properties exposed.

Can someone post a C# code snippet for getting items selected from the
outlook view control OR
Give some links/pointers on how to go about it?


Thanks & Regards
TT
 
J

Josh Einstein

You need to reference the Outlook PIA. Then cast the selection property to
type Microsoft.Office.Interop.Outlook.Selection such as:

using Outlook = Microsoft.Office.Interop.Outlook;
.....
Outlook.Selection currentSelection = viewCtl.Selection as Outlook.Selection;
if ( currentSelection != null && currentSelection.Count > 0 )
{
Outlook.MailItem currentMailItem = currentSelection[0] as
Outlook.MailItem;
if ( currentMailItem != null )
{
// you've got a selected mail item!
}
}
 

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