开发者

Sorting folder names in Outlook VSTO

I'm using VSTO to build an Outlook add-in. I have a wpf TreeView with binding

<HierarchicalDataTemplate ItemsSource="{Binding Folders}">
开发者_运维技巧

where Folders comes from a property that is set as

Folders = this.Application.ActiveExplorer().Session.Folders;

The folder hierarchy shows up correctly, but does not sort alphabetically like it does in Outlook. I don't see any methods to handle the sort natively. Just wondering if anyone else has done this and how they pulled it off.


I would sort the list myself. Assuming you want to sort by folder name, do this:

// Get the folders and sort them
SortedList<string, Folder> sortList = new SortedList<string, Folder>();
foreach (Folder nextFolder in this.Application.ActiveExplorer().Session.Folders)
    sortList.Add(nextFolder.Name, nextFolder);
List<Folder> finalList = new List<Folder>();
finalList.AddRange(sortList.Values);

// Set the sorted list as the source
Folders = finalList;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜