Free cookie consent management tool by TermsFeed Policy Generator

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)

File:
1 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)
Note: See TracChangeset for help on using the changeset viewer.