开发者

Sorting folder names in Outlook VSTO

开发者 https://www.devze.com 2023-03-20 01:27 出处:网络
I\'m using VSTO to build an Outlook add-in.I have a wpf TreeView with binding <HierarchicalDataTemplate ItemsSource=\"{Binding Folders}\">

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

精彩评论

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