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.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.