void FillAccountWithPermissonsSection(List <User> UserList) { var ret = from ul in UserList group ul by new { ul.Name, ul.SID } into gul orderby gul.Key.Name select new { gul.Key.SID, gul.Key.Name, Count = gul.Count(), InheritedCount = gul.Sum(p => (p.IsInherited) ? 1 : 0) }; foreach (var user in ret) { List <string> groups = (from ul in UserList where ul.SID == user.SID select ul.Group ).ToList(); var item = new AccountWithPermissions(iconUri_user, user.Name, user.Count, user.InheritedCount, user.SID, groups); listView_AccountWithPermissions.Items.Add(item); } }
private void ListViewItem_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (!(listView_AccountWithPermissions.SelectedItem is AccountWithPermissions selUser)) { return; } #region Lösche Gruppen unter dem User List <int> toRemove = new List <int>(); for (int i = listView_AccountWithPermissions.SelectedIndex + 1; i < listView_AccountWithPermissions.Items.Count; i++) { var checkItem = listView_AccountWithPermissions.Items.GetItemAt(i); AccountWithPermissions _item = checkItem as AccountWithPermissions; if (_item.IconGroup == null) { break; } else { toRemove.Add(i); //listView_AccountWithPermissions.Items.RemoveAt(i); } } bool ifRemoved = false; if (toRemove.Count > 0) { for (int i = toRemove.Last(); i >= toRemove.First(); i--) { listView_AccountWithPermissions.Items.RemoveAt(i); ifRemoved = true; } } #endregion #region Fügt die Gruppen unter dem User ein if (!ifRemoved) { foreach (var group in selUser.Groups) { AccountWithPermissions groupItem = new AccountWithPermissions(iconUri_group, group); listView_AccountWithPermissions.Items.Insert(listView_AccountWithPermissions.SelectedIndex + 1, groupItem); } } #endregion }