- Timestamp:
- 04/16/10 01:49:10 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core.Views/3.3/ItemListView.cs
r3341 r3362 92 92 Caption = "Item List"; 93 93 while (itemsListView.Items.Count > 0) RemoveListViewItem(itemsListView.Items[0]); 94 itemsListView.Enabled = false;95 detailsGroupBox.Enabled = false;96 94 viewHost.Content = null; 97 addButton.Enabled = false;98 moveUpButton.Enabled = false;99 moveDownButton.Enabled = false;100 removeButton.Enabled = false;101 102 95 if (Content != null) { 103 96 Caption += " (" + Content.GetType().Name + ")"; 104 itemsListView.Enabled = true;105 addButton.Enabled = !Content.IsReadOnly;106 97 foreach (T item in Content) 107 98 AddListViewItem(CreateListViewItem(item)); 99 } 100 SetEnabledStateOfControls(); 101 } 102 103 protected override void OnReadOnlyChanged() { 104 base.OnReadOnlyChanged(); 105 SetEnabledStateOfControls(); 106 } 107 108 private void SetEnabledStateOfControls() { 109 if (Content == null) { 110 addButton.Enabled = false; 111 moveUpButton.Enabled = false; 112 moveDownButton.Enabled = false; 113 removeButton.Enabled = false; 114 itemsListView.Enabled = false; 115 detailsGroupBox.Enabled = false; 116 } else { 117 addButton.Enabled = !Content.IsReadOnly && !ReadOnly; 118 moveUpButton.Enabled = itemsListView.SelectedItems.Count == 1 && 119 itemsListView.SelectedIndices[0] != 0 && 120 !Content.IsReadOnly && !ReadOnly; 121 moveDownButton.Enabled = itemsListView.SelectedItems.Count == 1 && 122 itemsListView.SelectedIndices[0] != itemsListView.Items.Count - 1 && 123 !Content.IsReadOnly && !ReadOnly; 124 removeButton.Enabled = itemsListView.SelectedItems.Count > 0 && 125 !Content.IsReadOnly && !ReadOnly; 126 itemsListView.Enabled = true; 127 detailsGroupBox.Enabled = true; 128 viewHost.ReadOnly = ReadOnly; 108 129 } 109 130 } … … 131 152 ((T)listViewItem.Tag).ItemImageChanged += new EventHandler(Item_ItemImageChanged); 132 153 ((T)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged); 154 AdjustListViewColumnSizes(); 133 155 } 134 156 protected virtual void InsertListViewItem(int index, ListViewItem listViewItem) { … … 136 158 ((T)listViewItem.Tag).ItemImageChanged += new EventHandler(Item_ItemImageChanged); 137 159 ((T)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged); 160 AdjustListViewColumnSizes(); 138 161 } 139 162 protected virtual void RemoveListViewItem(ListViewItem listViewItem) { … … 156 179 } 157 180 181 #region ListView Events 158 182 protected virtual void itemsListView_SelectedIndexChanged(object sender, EventArgs e) { 159 183 moveUpButton.Enabled = itemsListView.SelectedItems.Count == 1 && 160 184 itemsListView.SelectedIndices[0] != 0 && 161 !Content.IsReadOnly ;185 !Content.IsReadOnly && !ReadOnly; 162 186 moveDownButton.Enabled = itemsListView.SelectedItems.Count == 1 && 163 187 itemsListView.SelectedIndices[0] != itemsListView.Items.Count - 1 && 164 !Content.IsReadOnly ;188 !Content.IsReadOnly && !ReadOnly; 165 189 removeButton.Enabled = itemsListView.SelectedItems.Count > 0 && 166 !Content.IsReadOnly ;190 !Content.IsReadOnly && !ReadOnly; 167 191 168 192 if (itemsListView.SelectedItems.Count == 1) { … … 177 201 } 178 202 179 #region ListView Events180 protected virtual void itemsListView_SizeChanged(object sender, EventArgs e) {181 if (itemsListView.Columns.Count > 0)182 itemsListView.Columns[0].Width = Math.Max(0, itemsListView.Width - 25);183 }184 185 203 protected virtual void itemsListView_KeyDown(object sender, KeyEventArgs e) { 186 204 if (e.KeyCode == Keys.Delete) { 187 if ((itemsListView.SelectedItems.Count > 0) && !Content.IsReadOnly ) {205 if ((itemsListView.SelectedItems.Count > 0) && !Content.IsReadOnly && !ReadOnly) { 188 206 foreach (ListViewItem item in itemsListView.SelectedItems) 189 207 Content.RemoveAt(item.Index); … … 195 213 if (itemsListView.SelectedItems.Count == 1) { 196 214 T item = (T)itemsListView.SelectedItems[0].Tag; 197 IView view = MainFormManager.CreateDefaultView(item );215 IView view = MainFormManager.CreateDefaultView(item, ReadOnly); 198 216 if (view != null) view.Show(); 199 217 } … … 206 224 data.SetData("Type", item.GetType()); 207 225 data.SetData("Value", item); 208 if (Content.IsReadOnly ) {226 if (Content.IsReadOnly || ReadOnly) { 209 227 DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link); 210 228 } else { … … 217 235 e.Effect = DragDropEffects.None; 218 236 Type type = e.Data.GetData("Type") as Type; 219 if ( (!Content.IsReadOnly)&& (type != null) && (typeof(T).IsAssignableFrom(type))) {237 if (!Content.IsReadOnly && !ReadOnly && (type != null) && (typeof(T).IsAssignableFrom(type))) { 220 238 if ((e.KeyState & 8) == 8) e.Effect = DragDropEffects.Copy; // CTRL key 221 239 else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key … … 360 378 UpdateListViewItemText(listViewItem); 361 379 } 380 AdjustListViewColumnSizes(); 381 } 382 } 383 #endregion 384 385 #region Helpers 386 protected virtual void AdjustListViewColumnSizes() { 387 if (itemsListView.Items.Count > 0) { 388 for (int i = 0; i < itemsListView.Columns.Count; i++) 389 itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); 362 390 } 363 391 }
Note: See TracChangeset
for help on using the changeset viewer.