Index: trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.cs
===================================================================
--- trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.cs	(revision 5042)
+++ trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.cs	(revision 5057)
@@ -34,4 +34,5 @@
   [Content(typeof(IItemCollection<>), false)]
   public partial class ItemCollectionView<T> : ItemView where T : class, IItem {
+    private Dictionary<T, List<ListViewItem>> listViewItemMapping;
     protected TypeSelectorDialog typeSelectorDialog;
 
@@ -47,4 +48,5 @@
     public ItemCollectionView() {
       InitializeComponent();
+      listViewItemMapping = new Dictionary<T, List<ListViewItem>>();
     }
 
@@ -65,4 +67,5 @@
       base.OnContentChanged();
       while (itemsListView.Items.Count > 0) RemoveListViewItem(itemsListView.Items[0]);
+      RebuildImageList();
       viewHost.Content = null;
       if (Content != null) {
@@ -105,6 +108,5 @@
         try {
           return (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
-        }
-        catch (Exception ex) {
+        } catch (Exception ex) {
           ErrorHandling.ShowErrorDialog(this, ex);
         }
@@ -122,17 +124,23 @@
     }
     protected virtual void AddListViewItem(ListViewItem listViewItem) {
+      T item = (listViewItem.Tag as T);
       itemsListView.Items.Add(listViewItem);
-      ((T)listViewItem.Tag).ItemImageChanged += new EventHandler(Item_ItemImageChanged);
-      ((T)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged);
+      item.ItemImageChanged += new EventHandler(Item_ItemImageChanged);
+      item.ToStringChanged += new EventHandler(Item_ToStringChanged);
+      if (!listViewItemMapping.ContainsKey(item))
+        listViewItemMapping.Add(item, new List<ListViewItem>());
+      listViewItemMapping[item].Add(listViewItem);
       sortAscendingButton.Enabled = itemsListView.Items.Count > 1;
       sortDescendingButton.Enabled = itemsListView.Items.Count > 1;
     }
     protected virtual void RemoveListViewItem(ListViewItem listViewItem) {
-      ((T)listViewItem.Tag).ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
-      ((T)listViewItem.Tag).ToStringChanged -= new EventHandler(Item_ToStringChanged);
+      T item = (listViewItem.Tag as T);
+      listViewItemMapping[item].Remove(listViewItem);
+      if (listViewItemMapping[item].Count == 0) {
+        listViewItemMapping.Remove(item);
+        item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
+        item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
+      }
       listViewItem.Remove();
-      foreach (ListViewItem other in itemsListView.Items)
-        if (other.ImageIndex > listViewItem.ImageIndex) other.ImageIndex--;
-      itemsListView.SmallImageList.Images.RemoveAt(listViewItem.ImageIndex);
       sortAscendingButton.Enabled = itemsListView.Items.Count > 1;
       sortDescendingButton.Enabled = itemsListView.Items.Count > 1;
@@ -149,8 +157,5 @@
     }
     protected virtual IEnumerable<ListViewItem> GetListViewItemsForItem(T item) {
-      foreach (ListViewItem listViewItem in itemsListView.Items) {
-        if (((T)listViewItem.Tag) == item)
-          yield return listViewItem;
-      }
+      return listViewItemMapping[item];
     }
 
@@ -278,4 +283,5 @@
           if (listviewItem != null) RemoveListViewItem(listviewItem);
         }
+        RebuildImageList();
       }
     }
@@ -289,4 +295,5 @@
           if (listviewItem != null) RemoveListViewItem(listviewItem);
         }
+        RebuildImageList();
         foreach (T item in e.Items)
           AddListViewItem(CreateListViewItem(item));
@@ -328,4 +335,11 @@
       }
     }
+    private void RebuildImageList() {
+      itemsListView.SmallImageList.Images.Clear();
+      foreach (ListViewItem item in itemsListView.Items) {
+        itemsListView.SmallImageList.Images.Add(((T)item.Tag).ItemImage);
+        item.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
+      }
+    }
     #endregion
   }
