开发者

In an Outlook VSTO addin how do I clear the current selection?

开发者 https://www.devze.com 2023-04-09 19:08 出处:网络
From within an Outlook VSTO addin I want to开发者_如何转开发 clear the current selection. Is there an API for this?My current hack it to temporarily select the sent folder.

From within an Outlook VSTO addin I want to开发者_如何转开发 clear the current selection. Is there an API for this?


My current hack it to temporarily select the sent folder.

void ClearSelection(IRibbonControl control)
{
    //Here be dragons
    //Ok this looks like pointless code but it is necessary. 
    //For multiple items we are doing it in a background thread. 
    //There is a "feature" in outlook that means you cant delete 
    //the current selected item from a background thread. 
    //So we need this to clear the selection
    //and NO "control.Explorer().ClearSelection();" does not work.
    var explorer = GetExplorer(control);
    var currentFolder = explorer.CurrentFolder;
    var session = ThisAddIn.Application.Session;
    var sentFolder = session.GetDefaultFolder(OlDefaultFolders.olFolderSentMail);
    explorer.CurrentFolder = sentFolder;
    explorer.CurrentFolder = currentFolder;
}

Explorer GetExplorer(IRibbonControl control)
{
    dynamic context = control.Context;
    var explorer = context.Parent as Explorer;
    if (explorer == null)
    {
        var application = (ApplicationClass)context.Parent;
        explorer = application.ActiveExplorer();
    }
    return explorer;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号