2011-09-30 37 views
0

從Outlook VSTO插件中,我想清除當前的選擇。 是否有這樣的API?在Outlook VSTO插件中,如何清除當前選擇?

+0

你有沒有想過如何做到這一點呢? –

+0

@aloneguid不,我沒有解決這個問題。我制定瞭如何清除足夠用於我目的的選擇 – Simon

+0

如何清除選擇? :) –

回答

1

我目前破解它暫時選擇發送的文件夾。

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

它看起來很奇怪,但這就像在OL世界的一切,但它的作品!謝謝! –

相關問題