Changeset 665
- Timestamp:
- 10/15/08 00:27:44 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Data/ItemListView_T.cs
r40 r665 65 65 detailsGroupBox.Enabled = false; 66 66 removeButton.Enabled = false; 67 if 67 if(ItemList == null) { 68 68 typeTextBox.Text = ""; 69 69 splitContainer.Enabled = false; … … 71 71 typeTextBox.Text = typeof(T).FullName; 72 72 splitContainer.Enabled = true; 73 foreach 73 foreach(ListViewItem item in itemsListView.Items) { 74 74 ((IItem)item.Tag).Changed -= new EventHandler(Item_Changed); 75 75 } 76 76 itemsListView.Items.Clear(); 77 foreach 77 foreach(IItem data in ItemList) { 78 78 ListViewItem item = new ListViewItem(); 79 79 item.Text = data.ToString(); … … 86 86 87 87 private void elementsListView_SelectedIndexChanged(object sender, EventArgs e) { 88 if 88 if(detailsGroupBox.Controls.Count > 0) 89 89 detailsGroupBox.Controls[0].Dispose(); 90 90 detailsGroupBox.Controls.Clear(); 91 91 detailsGroupBox.Enabled = false; 92 92 removeButton.Enabled = false; 93 if 93 if(itemsListView.SelectedItems.Count > 0) { 94 94 removeButton.Enabled = true; 95 95 } 96 if 96 if(itemsListView.SelectedItems.Count == 1) { 97 97 IItem data = (IItem)itemsListView.SelectedItems[0].Tag; 98 98 Control view = (Control)data.CreateView(); … … 105 105 #region Size Changed Events 106 106 private void elementsListView_SizeChanged(object sender, EventArgs e) { 107 if 107 if(itemsListView.Columns.Count > 0) 108 108 itemsListView.Columns[0].Width = Math.Max(0, itemsListView.Width - 25); 109 109 } … … 112 112 #region Key Events 113 113 private void elementsListView_KeyDown(object sender, KeyEventArgs e) { 114 if 115 while 114 if(e.KeyCode == Keys.Delete) { 115 while(itemsListView.SelectedIndices.Count > 0) 116 116 ItemList.RemoveAt(itemsListView.SelectedIndices[0]); 117 e.Handled = true; 118 } else if((e.KeyCode == Keys.C) && (e.Modifiers == Keys.Control)) { 119 // copy contents of itemlist to clipboard 120 StringBuilder buffer = new StringBuilder(); 121 for(int i = 0; i < itemsListView.Items.Count; i++) { 122 buffer.Append(itemsListView.Items[i].Text); 123 buffer.Append("\n"); 124 } 125 Clipboard.SetText(buffer.ToString()); 126 e.Handled = true; 117 127 } 118 128 } … … 121 131 #region Button Events 122 132 private void addButton_Click(object sender, EventArgs e) { 123 if 133 if(chooseItemDialog == null) { 124 134 chooseItemDialog = new ChooseItemDialog(typeof(T)); 125 135 chooseItemDialog.Caption = "Add Item"; 126 136 } 127 if 137 if(chooseItemDialog.ShowDialog(this) == DialogResult.OK) { 128 138 try { 129 139 ItemList.Add((T)chooseItemDialog.Item); 130 } 131 catch (Exception ex) { 140 } catch(Exception ex) { 132 141 Auxiliary.ShowErrorMessageBox(ex); 133 142 } … … 135 144 } 136 145 private void removeButton_Click(object sender, EventArgs e) { 137 while 146 while(itemsListView.SelectedIndices.Count > 0) 138 147 ItemList.RemoveAt(itemsListView.SelectedIndices[0]); 139 148 } … … 151 160 private void elementsListView_DragEnter(object sender, DragEventArgs e) { 152 161 e.Effect = DragDropEffects.None; 153 if 162 if(e.Data.GetDataPresent("IItem")) { 154 163 Point p = itemsListView.PointToClient(new Point(e.X, e.Y)); 155 164 ListViewItem item = itemsListView.GetItemAt(p.X, p.Y); 156 if 165 if(item != null) 157 166 e.Effect = DragDropEffects.Move; 158 167 } … … 160 169 private void elementsListView_DragOver(object sender, DragEventArgs e) { 161 170 e.Effect = DragDropEffects.None; 162 if 171 if(e.Data.GetDataPresent("IItem")) { 163 172 Point p = itemsListView.PointToClient(new Point(e.X, e.Y)); 164 173 ListViewItem item = itemsListView.GetItemAt(p.X, p.Y); 165 if 174 if(item != null) 166 175 e.Effect = DragDropEffects.Move; 167 176 } 168 177 } 169 178 private void elementsListView_DragDrop(object sender, DragEventArgs e) { 170 if 171 if 179 if(e.Effect != DragDropEffects.None) { 180 if(e.Data.GetDataPresent("IItem")) { 172 181 IItem data = (IItem)e.Data.GetData("IItem"); 173 182 Point p = itemsListView.PointToClient(new Point(e.X, e.Y)); 174 183 ListViewItem item = itemsListView.GetItemAt(p.X, p.Y); 175 if 184 if(item != null) { 176 185 int index = item.Index; 177 186 ItemList.Remove((T)data); … … 187 196 #region Item and Item List Events 188 197 private void ItemList_ItemInserted(object sender, ItemIndexEventArgs e) { 189 if 198 if(InvokeRequired) 190 199 Invoke(new EventHandler<ItemIndexEventArgs>(ItemList_ItemInserted), sender, e); 191 200 else { … … 198 207 } 199 208 private void ItemList_ItemRemoved(object sender, ItemIndexEventArgs e) { 200 if 209 if(InvokeRequired) 201 210 Invoke(new EventHandler<ItemIndexEventArgs>(ItemList_ItemRemoved), sender, e); 202 211 else { … … 209 218 } 210 219 private void Item_Changed(object sender, EventArgs e) { 211 if 220 if(InvokeRequired) 212 221 Invoke(new EventHandler(Item_Changed), sender, e); 213 222 else { 214 223 IItem data = (IItem)sender; 215 foreach 216 if 224 foreach(ListViewItem item in itemsListView.Items) { 225 if(item.Tag == data) 217 226 item.Text = data.ToString(); 218 227 }
Note: See TracChangeset
for help on using the changeset viewer.