Changeset 17957


Ignore:
Timestamp:
04/21/21 22:50:09 (2 weeks ago)
Author:
mkommend
Message:

#2521: Fixed bugs in resultsProducingItemView (toString changes of items, removing of parametes / results not working).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization.Views/3.3/ResultsProducingItemView.cs

    r17953 r17957  
    9090      base.RegisterContentEvents();
    9191      RegisterContentParametersEvents();
    92       RegisterContentResultsEents();
     92      RegisterContentResultsEvents();
    9393    }
    9494    private void RegisterContentParametersEvents() {
    9595      Content.Parameters.ItemsAdded += ParametersOnItemsChanged;
    96       Content.Parameters.ItemsRemoved += ParametersOnItemsChanged;
     96      Content.Parameters.ItemsRemoved += ParametersOnItemsRemoved;
    9797      Content.Parameters.ItemsReplaced += ParametersOnItemsChanged;
    9898      Content.Parameters.CollectionReset += ParametersOnItemsChanged;
    99     }
    100     private void RegisterContentResultsEents() {
     99
     100      foreach (var item in Content.Parameters) {
     101        RegisterItemEvents(item);
     102      }
     103    }
     104    private void RegisterContentResultsEvents() {
    101105      Content.Results.ItemsAdded += ResultsOnItemsChanged;
    102       Content.Results.ItemsRemoved += ResultsOnItemsChanged;
     106      Content.Results.ItemsRemoved += ResultsOnItemsRemoved;
    103107      Content.Results.ItemsReplaced += ResultsOnItemsChanged;
    104108      Content.Results.CollectionReset += ResultsOnItemsChanged;
     109
     110      foreach (var item in Content.Results) {
     111        RegisterItemEvents(item);
     112      }
    105113    }
    106114    protected virtual void RegisterItemEvents(IItem item) {
     
    120128    private void DeregisterContentParametersEvents() {
    121129      Content.Parameters.ItemsAdded -= ParametersOnItemsChanged;
    122       Content.Parameters.ItemsRemoved -= ParametersOnItemsChanged;
     130      Content.Parameters.ItemsRemoved -= ParametersOnItemsRemoved;
    123131      Content.Parameters.ItemsReplaced -= ParametersOnItemsChanged;
    124132      Content.Parameters.CollectionReset -= ParametersOnItemsChanged;
     
    126134    private void DeregisterContentResultsEvents() {
    127135      Content.Results.ItemsAdded -= ResultsOnItemsChanged;
    128       Content.Results.ItemsRemoved -= ResultsOnItemsChanged;
     136      Content.Results.ItemsRemoved -= ResultsOnItemsRemoved;
    129137      Content.Results.ItemsReplaced -= ResultsOnItemsChanged;
    130138      Content.Results.CollectionReset -= ResultsOnItemsChanged;
     
    155163      }
    156164      itemToListViewItem.Clear();
    157 
    158       var counter = 0;
    159       foreach (var item in listView.Items.OfType<ListViewItem>().OrderBy(x => x.ImageIndex).ToList())
    160         item.ImageIndex = counter++;
    161165      listView.EndUpdate();
    162166
     
    191195      foreach (var item in e.Items) {
    192196        var listViewItem = CreateListViewItem(item, parameterGroup);
     197        RegisterItemEvents(item);
    193198        listView.Items.Add(listViewItem);
    194199        itemToListViewItem[item] = listViewItem;
    195200      }
    196201      AdjustListViewColumnSizes();
     202    }
     203    private void ParametersOnItemsRemoved(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
     204      var eventArgs = new CollectionItemsChangedEventArgs<IParameter>(new IParameter[0], e.Items);
     205      ParametersOnItemsChanged(sender, eventArgs);
    197206    }
    198207
     
    204213      foreach (var item in e.Items) {
    205214        var listViewItem = CreateListViewItem(item, resultsGroup);
     215        RegisterItemEvents(item);
    206216        listView.Items.Add(listViewItem);
    207217        itemToListViewItem[item] = listViewItem;
    208218      }
    209219      AdjustListViewColumnSizes();
     220    }
     221    private void ResultsOnItemsRemoved(object sender, CollectionItemsChangedEventArgs<IResult> e) {
     222      var eventArgs = new CollectionItemsChangedEventArgs<IResult>(new IResult[0], e.Items);
     223      ResultsOnItemsChanged(sender, eventArgs);
    210224    }
    211225
Note: See TracChangeset for help on using the changeset viewer.