Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4203 for trunk


Ignore:
Timestamp:
08/12/10 11:57:28 (14 years ago)
Author:
mkommend
Message:

Refactored the code to remove a ListViewItems to use linq extension and added a comment to explain why only the first matching ListViewItem is removed. (ticket #1141)

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.cs

    r4099 r4203  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using System.Windows.Forms;
    2526using HeuristicLab.Collections;
     
    271272      else {
    272273        foreach (T item in e.Items) {
    273           foreach (ListViewItem listViewItem in GetListViewItemsForItem(item)) {
    274             RemoveListViewItem(listViewItem);
    275             break;
    276           }
     274          //remove only the first matching ListViewItem, because the IItem could be contained multiple times in the ItemCollection
     275          ListViewItem listviewItem = GetListViewItemsForItem(item).FirstOrDefault();
     276          if (listviewItem != null)
     277            RemoveListViewItem(listviewItem);
    277278        }
    278279      }
     
    283284      else {
    284285        foreach (T item in e.OldItems) {
    285           foreach (ListViewItem listViewItem in GetListViewItemsForItem(item)) {
    286             RemoveListViewItem(listViewItem);
    287             break;
    288           }
     286          //remove only the first matching ListViewItem, because the IItem could be contained multiple times in the ItemCollection
     287          ListViewItem listviewItem = GetListViewItemsForItem(item).FirstOrDefault();
     288          if (listviewItem != null)
     289            RemoveListViewItem(listviewItem);
    289290        }
    290291        foreach (T item in e.Items)
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.cs

    r4200 r4203  
    316316        DeregisterRunEvents(e.Items);
    317317        foreach (IRun item in e.Items) {
    318           foreach (ListViewItem listViewItem in GetListViewItemsForItem(item)) {
    319             RemoveListViewItem(listViewItem);
    320             break;
    321           }
     318          //remove only the first matching ListViewItem, because the IRun could be contained multiple times in the ItemCollection
     319          ListViewItem listviewItem = GetListViewItemsForItem(item).FirstOrDefault();
     320          if (listviewItem != null)
     321            RemoveListViewItem(listviewItem);
    322322        }
    323323        analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0;
     
    332332        DeregisterRunEvents(e.OldItems);
    333333        foreach (IRun item in e.OldItems) {
    334           foreach (ListViewItem listViewItem in GetListViewItemsForItem(item)) {
    335             RemoveListViewItem(listViewItem);
    336             break;
    337           }
     334          //remove only the first matching ListViewItem, because the IRun could be contained multiple times in the ItemCollection
     335          ListViewItem listviewItem = GetListViewItemsForItem(item).FirstOrDefault();
     336          if (listviewItem != null)
     337            RemoveListViewItem(listviewItem);
    338338        }
    339339        RegisterRunEvents(e.Items);
Note: See TracChangeset for help on using the changeset viewer.