Beispiel #1
0
        private async void FillWatchedFoldersListView()
        {
            var sortByName = Properties.Settings.Default.SortAttribute.ToLowerInvariant() == "name";
            Func <Folder, IComparable> sortbyFunc = (Folder folder) =>
            {
                if (sortByName)
                {
                    return(folder.Name);
                }
                return(folder.DateAdded);
            };

            var folders = await Task.Run(() => folderManager.GetWatchedFolders());

            IOrderedEnumerable <Folder> orderedFolders = folders.OrderBy(sortbyFunc);

            if (Properties.Settings.Default.SortOrder == SortOrder.Descending)
            {
                orderedFolders = folders.OrderByDescending(sortbyFunc);
            }

            var items = new List <ListViewItem>();

            foreach (var folder in orderedFolders)
            {
                var item = new ListViewItem(folder.Name, 0)
                {
                    ImageIndex = 0
                };
                item.SubItems.Add(folder.Path);
                item.SubItems.Add(folder.DateAdded.ToShortDateString());
                items.Add(item);
            }
            watchedFoldersListView.Items.Clear();
            watchedFoldersListView.Items.AddRange(items.ToArray());
            watchedFoldersListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
        }