Change outlook mailitem selection c#

流过昼夜 提交于 2019-12-06 11:37:25

Use Explorer.ClearSelection() and then Explorer.AddToSelection(). You should use Explorer.IsItemSelectableInView() before calling AddToSelection() to ensure the item you want to select exists in the current explorer view.

Application.ActiveExplorer() will give you the current active explorer if it exists.

Here is a sample snippet taken from here (slightly modified to check IsItemSelectableInView).

Outlook._Explorer explorer = OutlookApp.ActiveExplorer();  // get active explorer
explorer.ClearSelection(); // remove current selection
Outlook.NameSpace ns = OutlookApp.Session; 
object item = ns.GetItemFromID(entryId, Type.Missing); // retrieve item
if (explorer.IsItemSelectableInView(item)) // ensure item is in current view
  explorer.AddToSelection(item); // change explorer selection
else
  // TODO: change current view so that item is selectable
Marshal.ReleaseComObject(item); 
Marshal.ReleaseComObject(ns); 
Marshal.ReleaseComObject(explorer); 

To change the current Explorer view you can use Explorer.CurrentFolder or Explorer.CurrentView

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!