在 Outlook VSTO 插件中如何清除当前选择?

发布于 2024-12-07 02:23:24 字数 46 浏览 0 评论 0原文

我想从 Outlook VSTO 插件中清除当前选择。 有这方面的API吗?

From within an Outlook VSTO addin I want to clear the current selection.
Is there an API for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不交电费瞎发啥光 2024-12-14 02:23:24

我目前的破解方法是暂时选择发送的文件夹。

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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文