/// <summary> /// Выполняет группировку элементов /// </summary> protected override void SetGroupsToItems() { itemsListView.Groups.Clear(); if (OldColumnIndex != 9) { foreach (var item in ListViewItemList) { var temp = ListViewGroupHelper.GetGroupString(item.Tag); itemsListView.Groups.Add(temp, temp); item.Group = itemsListView.Groups[temp]; } } else { //Группировка элементов по датам выполнения var groupedItems = ListViewItemList.Where(lvi => lvi.Tag != null && lvi.Tag is NextPerformance) .GroupBy(lvi => Convert.ToDateTime(((NextPerformance)lvi.Tag).PerformanceDate).Date); foreach (var groupedItem in groupedItems) { //Собрание всех выполнений на данную дату в одну коллекцию var performances = groupedItem.Select(lvi => lvi.Tag as NextPerformance).ToList(); var temp = ListViewGroupHelper.GetGroupStringByPerformanceDate(performances, groupedItem.Key.Date); itemsListView.Groups.Add(temp, temp); foreach (var item in groupedItem) { item.Group = itemsListView.Groups[temp]; } } } }
protected override void SortItems(int columnIndex) { if (OldColumnIndex != columnIndex) { SortMultiplier = -1; } if (SortMultiplier == 1) { SortMultiplier = -1; } else { SortMultiplier = 1; } itemsListView.Items.Clear(); SetGroupsToItems(); List <ListViewItem> resultList = new List <ListViewItem>(); if (columnIndex <= 6 || columnIndex == 19 || columnIndex == 20) { ListViewItemList.Sort(new BaseListViewComparer(columnIndex, SortMultiplier)); //добавление остальных подзадач foreach (ListViewItem item in ListViewItemList) { if (item.Tag is Component) { resultList.Add(item); Component component = (Component)item.Tag; IEnumerable <ListViewItem> items = ListViewItemList .Where(lvi => lvi.Tag is ComponentDirective && ((ComponentDirective)lvi.Tag).ComponentId == component.ItemId); foreach (ListViewItem listViewItem in items) { listViewItem.Group = item.Group; } resultList.AddRange(items); } } } else { //добавление остальных подзадач foreach (ListViewItem item in ListViewItemList) { if (item.Tag is Component) { resultList.Add(item); Component component = (Component)item.Tag; IEnumerable <ListViewItem> items = ListViewItemList .Where(lvi => lvi.Tag is ComponentDirective && ((ComponentDirective)lvi.Tag).ComponentId == component.ItemId); foreach (ListViewItem listViewItem in items) { listViewItem.Group = item.Group; } resultList.AddRange(items); } } resultList.Sort(new BaseListViewComparer(columnIndex, SortMultiplier)); } itemsListView.Items.AddRange(resultList.ToArray()); OldColumnIndex = columnIndex; }