Changeset 17009 for trunk/HeuristicLab.Core.Views
- Timestamp:
- 06/14/19 13:40:49 (5 years ago)
- Location:
- trunk/HeuristicLab.Core.Views/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Core.Views/3.3/CheckedItemCollectionView.cs
r16565 r17009 34 34 [Content(typeof(ReadOnlyCheckedItemCollection<>), true)] 35 35 public partial class CheckedItemCollectionView<T> : ItemCollectionView<T> where T : class, IItem { 36 private bool suppressCheckedEvents; 37 36 38 public new ICheckedItemCollection<T> Content { 37 39 get { return (ICheckedItemCollection<T>)base.Content; } … … 84 86 doubleClick = false; 85 87 } else { 88 bool check = e.NewValue == CheckState.Checked; 86 89 var checkedItem = (T)itemsListView.Items[e.Index].Tag; 87 bool check = e.NewValue == CheckState.Checked; 88 if (Content.ItemChecked(checkedItem) != check) { 89 if (!ReadOnly && !Locked) Content.SetItemCheckedState(checkedItem, check); 90 else e.NewValue = e.CurrentValue; 91 } 90 if (Content.ItemChecked(checkedItem) == check) return; 91 92 suppressCheckedEvents = true; 93 try { 94 if (itemsListView.SelectedIndices.Count > 1 95 && itemsListView.SelectedIndices.Contains(e.Index)) { 96 if (!ReadOnly && !Locked) Content.SetItemCheckedState(itemsListView.SelectedItems.Cast<ListViewItem>().Select(x => (T)x.Tag), check); 97 else e.NewValue = e.CurrentValue; 98 } else { 99 if (!ReadOnly && !Locked) Content.SetItemCheckedState(checkedItem, check); 100 else e.NewValue = e.CurrentValue; 101 } 102 } finally { suppressCheckedEvents = false; } 92 103 } 93 104 } 94 protected void itemsListView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {105 protected void itemsListView_MouseDown(object sender, MouseEventArgs e) { 95 106 if (e.Clicks > 1) 96 107 doubleClick = true; … … 103 114 Invoke(new CollectionItemsChangedEventHandler<T>(Content_CheckedItemsChanged), sender, e); 104 115 else { 105 UpdateCheckedItemState(e.Items);116 if (!suppressCheckedEvents) UpdateCheckedItemState(e.Items); 106 117 SetNumberOfCheckItems(); 107 118 } … … 130 141 131 142 private void UpdateCheckedItemState(IEnumerable<T> items) { 132 foreach (T item in items) { 133 foreach (ListViewItem listViewItem in GetListViewItemsForItem(item)) { 134 var isChecked = Content.ItemChecked(item); 135 if (listViewItem.Checked != isChecked) 136 listViewItem.Checked = isChecked; 143 itemsListView.BeginUpdate(); 144 try { 145 foreach (T item in items) { 146 foreach (ListViewItem listViewItem in GetListViewItemsForItem(item)) { 147 var isChecked = Content.ItemChecked(item); 148 if (listViewItem.Checked != isChecked) 149 listViewItem.Checked = isChecked; 150 } 137 151 } 138 } 152 } finally { itemsListView.EndUpdate(); itemsListView.Refresh(); } 139 153 } 140 154 } -
trunk/HeuristicLab.Core.Views/3.3/CheckedItemListView.cs
r16565 r17009 37 37 [Content(typeof(ReadOnlyCheckedItemList<>), true)] 38 38 public partial class CheckedItemListView<T> : ItemListView<T> where T : class, IItem { 39 private bool suppressCheckedEvents; 40 39 41 public new ICheckedItemList<T> Content { 40 42 get { return (ICheckedItemList<T>)base.Content; } … … 86 88 doubleClick = false; 87 89 } else { 88 var checkedItem = (T)itemsListView.Items[e.Index].Tag;89 90 bool check = e.NewValue == CheckState.Checked; 90 if (Content.ItemChecked(checkedItem) != check) { 91 if (!ReadOnly && !Locked) Content.SetItemCheckedState(checkedItem, check); 92 else e.NewValue = e.CurrentValue; 93 } 91 if (Content.ItemChecked(e.Index) == check) return; 92 93 suppressCheckedEvents = true; 94 try { 95 if (itemsListView.SelectedIndices.Count > 1 96 && itemsListView.SelectedIndices.Contains(e.Index)) { 97 if (!ReadOnly && !Locked) Content.SetItemCheckedState(itemsListView.SelectedIndices.Cast<int>(), check); 98 else e.NewValue = e.CurrentValue; 99 } else { 100 var checkedItem = (T)itemsListView.Items[e.Index].Tag; 101 if (!ReadOnly && !Locked) Content.SetItemCheckedState(checkedItem, check); 102 else e.NewValue = e.CurrentValue; 103 } 104 } finally { suppressCheckedEvents = false; } 94 105 } 95 106 } … … 139 150 Invoke(new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_CheckedItemsChanged), sender, e); 140 151 else { 141 UpdateCheckedItemState(e.Items);152 if (!suppressCheckedEvents) UpdateCheckedItemState(e.Items); 142 153 SetNumberOfCheckItems(); 143 154 } … … 175 186 176 187 private void UpdateCheckedItemState(IEnumerable<IndexedItem<T>> items) { 177 foreach (var item in items) { 178 var isChecked = Content.ItemChecked(item.Value); 179 if (itemsListView.Items[item.Index].Checked != isChecked) 180 itemsListView.Items[item.Index].Checked = isChecked; 181 } 188 itemsListView.BeginUpdate(); 189 try { 190 foreach (var item in items) { 191 var isChecked = Content.ItemChecked(item.Value); 192 if (itemsListView.Items[item.Index].Checked != isChecked) 193 itemsListView.Items[item.Index].Checked = isChecked; 194 } 195 } finally { itemsListView.EndUpdate(); itemsListView.Refresh(); } 182 196 } 183 197 }
Note: See TracChangeset
for help on using the changeset viewer.