How to Capture Events for an Item selected in the Explorer?

Add-in Express™ Support Service
That's what is more important than anything else

How to Capture Events for an Item selected in the Explorer?
Using "OutlookItemEvents" example and _ExplorerSelectionChange event 
Tri Nguyen




Posts: 7
Joined: 2006-05-25
I am using Sergey's "OutlookItemEvents" example to learn how to capture Item events. It's been very helpful.

But now I would like to capture an Item's events when the user selects the item in the Explorer. I am having trouble with this.

Specifically, I am having trouble returning an Item from the Selection in the Explorer. I am using the adxOutlookEvents_ExplorerSelectionChange event:


		// added to capture events from items selected in the explorer
		private void adxOutlookEvents_ExplorerSelectionChange(object sender, object explorer)
		{
			if (canConnect)
			{
				Outlook._Explorer olExpl = explorer as Outlook._Explorer;
				Outlook._Inspector olInsp = olExpl.Selection.Item(1);
				itemEvents.ConnectTo(olInsp.CurrentItem, true);
			}
		}



The above doesn't work, but gives the flavor of what I want to do. I appreciate any help. Thanks.
Posted 25 May, 2006 15:12:15 Top
Sergey Grischenko


Add-in Express team


Posts: 7228
Joined: 2004-07-05
Hi Tri.

In this case you should use the OutlookItemsEvents class.
Please try the OutlookFolderItemsEvents example from the ADX installation package.
Posted 25 May, 2006 15:52:27 Top
Tri Nguyen




Posts: 7
Joined: 2006-05-25
Thanks for the quick reply, Sergey.

I looked at OutlookFolderItemsEvents example as you suggested. Maybe it's late in the day here and I'm tired, but I couldn't find a way to my goal. Was there something specific I was to find there?

Thanks,
Tri
Posted 25 May, 2006 18:32:48 Top
Sergey Grischenko


Add-in Express team


Posts: 7228
Joined: 2004-07-05
Hi Tri.

Specifically, I am having trouble returning an Item from the Selection in the Explorer.

Could you please explain the issue in more details? Do you get any error messages?
Posted 26 May, 2006 12:54:25 Top
Tri Nguyen




Posts: 7
Joined: 2006-05-25
Sergey,

What I want is simple. However, I am a beginner, so bear with me please.

In Outlook, I want to capture an item's "ReplyAll." This I have accomplished already by using AddinExpress.MSO.ADXOutlookItemEvents and overriding the ProcessReplyAll event. However, this works only when the user clicks "Reply to All" in an item's opened Inspector.

I also want to capture "ReplyAll" when the user replies from the Explorer (in other words, when user replies to an email directly from the email list view).

How do I do this? I thought to use ExplorerSelectionChange (an OutlookEvent) to connect the email currently selected in Explorer to ProcessReplyAll (an OutlookItemEvent). However, the object model won't return an Inspector from the Selection in the Explorer.


      private void adxOutlookEvents_ExplorerSelectionChange(object sender, object explorer)
      {
         if (canConnect)
         {
            Outlook._Explorer olExpl = explorer as Outlook._Explorer;
            Outlook._Inspector olInsp = olExpl.Selection.Item(1); ?????
            itemEvents.ConnectTo(olInsp.CurrentItem, true);
         }
      } 


Is this the wrong approach? Again, I am a beginner, so the obvious way may not be obvious to me.

Thanks again, Sergey.
Posted 30 May, 2006 13:00:56 Top
Sergey Grischenko


Add-in Express team


Posts: 7228
Joined: 2004-07-05
Hi Tri.

You just need to connect to the 'ReplyAll' button via the ADXBuiltInControl component. Then you can obtain the Selection interface (OutlookApp.ActiveExplorer().Selection) to detect an email item selected in the view.
Posted 31 May, 2006 10:16:23 Top
Brad Smith




Posts: 49
Joined: 2005-11-22
Just as a point of interest, there is one problem with hooking the toolbar button in this situation.
Unfortunately, there's a bug in Outlook (it's been reported to Microsoft, but they don't seem to understand that it's a bug) whereby the keyboard shortcuts (eg. Ctrl-R for Reply) does *not* trigger the toolbar button event.
The good news is that right-clicking an item and hitting Reply *does* work, as does selecting and going Actions|Reply. It's just the hotkey situation that's broken.
This is not an ADX limitation, it's an Outlook bug.

Eventually I'm going to have to deal with this in my code (right now we merely document that as a known limitation). It's going to be a while, but my most likely approach is going to be to trap the Explorer OnSelectionChange handler as well.

Tri, if you decide to keep playing with this, the item returned by the Selection collection is *not* of Inspectors (which don't exist in this case) but of actual items (MailItem, etc). I haven't tried, but you *may* be able to get away with something like:

itemEvents.ConnectTo(olExpl.Selection.Item(1), true);


although I'd definitely write the extra code to determine what *kind* of item is selected and act accordingly.

Brad.
Posted 31 May, 2006 11:46:39 Top
Sergey Grischenko


Add-in Express team


Posts: 7228
Joined: 2004-07-05
Hi Brad.

Thank you for help. The Ctrl+R shortcut can be overrided too.
It can be done via the ADXKeyboardShortcut component added in the latest ADX version.
Posted 31 May, 2006 13:03:02 Top
Tri Nguyen




Posts: 7
Joined: 2006-05-25
Tri, if you decide to keep playing with this, the item returned by the Selection collection is *not* of Inspectors (which don't exist in this case) but of actual items (MailItem, etc). I haven't tried, but you *may* be able to get away with something like:

itemEvents.ConnectTo(olExpl.Selection.Item(1), true);

although I'd definitely write the extra code to determine what *kind* of item is selected and act accordingly.


Thanks Brad! I tried it, and noticed that the Selection interface doesn't expose an Item method (the "Microsoft Outlook 2003 Visual Basic Reference" says it should). Very confusing! However, Selection does support IEnumerable, so you can iterate over it with foreach. For my purposes that was good enough. Here's the snippet that finally worked for me:


		private void adxBuiltInControl1_Action(object sender)
		{
			// I keyed the Id to 355, the Outlook's built-in "ReplyAll" control
			
			if (canConnect)
			{
				Outlook.Selection olSel = (Outlook.Selection)OutlookApp.ActiveExplorer().Selection;
				foreach (Object itm in olSel)
				{
					itemEvents.ConnectTo(itm,true);
				}
			}
		}


Thanks, everyone, for all your help.
Posted 31 May, 2006 16:21:09 Top
Tri Nguyen




Posts: 7
Joined: 2006-05-25
Hi Brad.

Thank you for help. The Ctrl+R shortcut can be overrided too.
It can be done via the ADXKeyboardShortcut component added in the latest ADX version.


Sergey, I would like to use the new ADXKeyboardShortcut component now. How can I get to it? And is there documentation? (I have the latest ADX.NET.)

Thanks,
Tri
Posted 09 Jun, 2006 16:34:17 Top