Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3775


Ignore:
Timestamp:
05/11/10 18:16:41 (15 years ago)
Author:
swagner
Message:

Implemented reviewers' comments (#893)

  • added automatic re-selection of elements in collection views when the content of the view is changed
Location:
trunk/sources
Files:
5 edited

Legend:

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

    r3764 r3775  
    8484    protected override void OnContentChanged() {
    8585      base.OnContentChanged();
     86
     87      int selectedIndex = -1;
     88      if (itemsListView.SelectedItems.Count == 1) selectedIndex = itemsListView.SelectedIndices[0];
     89
    8690      while (itemsListView.Items.Count > 0) RemoveListViewItem(itemsListView.Items[0]);
    8791      viewHost.Content = null;
     
    9094        foreach (T item in Content)
    9195          AddListViewItem(CreateListViewItem(item));
     96        if ((selectedIndex != -1) && (selectedIndex < itemsListView.Items.Count))
     97          itemsListView.Items[selectedIndex].Selected = true;
    9298      }
    9399      SetEnabledStateOfControls();
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemListView.cs

    r3764 r3775  
    8888    protected override void OnContentChanged() {
    8989      base.OnContentChanged();
     90
     91      int selectedIndex = -1;
     92      if (itemsListView.SelectedItems.Count == 1) selectedIndex = itemsListView.SelectedIndices[0];
     93
    9094      while (itemsListView.Items.Count > 0) RemoveListViewItem(itemsListView.Items[0]);
    9195      viewHost.Content = null;
     
    9397        foreach (T item in Content)
    9498          AddListViewItem(CreateListViewItem(item));
     99        if ((selectedIndex != -1) && (selectedIndex < itemsListView.Items.Count))
     100          itemsListView.Items[selectedIndex].Selected = true;
    95101      }
    96102      SetEnabledStateOfControls();
  • trunk/sources/HeuristicLab.Core.Views/3.3/NamedItemCollectionView.cs

    r3764 r3775  
    5151      base.RegisterContentEvents();
    5252      Content.ItemsReplaced += new CollectionItemsChangedEventHandler<T>(Content_ItemsReplaced);
     53    }
     54
     55    protected override void OnContentChanged() {
     56      string selectedName = null;
     57      if ((itemsListView.SelectedItems.Count == 1) && (itemsListView.SelectedItems[0].Tag != null))
     58        selectedName = ((T)itemsListView.SelectedItems[0].Tag).Name;
     59      base.OnContentChanged();
     60      if (selectedName != null) {
     61        foreach (ListViewItem item in itemsListView.Items) {
     62          if ((item.Tag != null) && (((T)item.Tag).Name.Equals(selectedName)))
     63            item.Selected = true;
     64        }
     65      }
    5366    }
    5467
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.cs

    r3764 r3775  
    9494    protected override void OnContentChanged() {
    9595      base.OnContentChanged();
     96
     97      string selectedName = null;
     98      if ((itemsListView.SelectedItems.Count == 1) && (itemsListView.SelectedItems[0].Tag != null))
     99        selectedName = ((IRun)itemsListView.SelectedItems[0].Tag).Name;
     100
    96101      while (itemsListView.Items.Count > 0) RemoveListViewItem(itemsListView.Items[0]);
    97102      viewHost.Content = null;
     
    105110        }
    106111        foreach (IRun item in Content) {
    107           AddListViewItem(CreateListViewItem(item));
     112          ListViewItem listViewItem = CreateListViewItem(item);
     113          AddListViewItem(listViewItem);
    108114          UpdateRun(item);
     115          if ((selectedName != null) && item.Name.Equals(selectedName))
     116            listViewItem.Selected = true;
    109117        }
    110118      } else {
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunView.cs

    r3766 r3775  
    2121
    2222using System;
     23using System.Linq;
    2324using System.Windows.Forms;
    2425using HeuristicLab.Common;
     
    6970    protected override void OnContentChanged() {
    7071      base.OnContentChanged();
    71       FillListView();
    72       viewHost.ViewType = null;
    7372      viewHost.Content = null;
    7473      if (Content != null)
    7574        UpdateColorPictureBox();
     75      FillListView();
    7676
    7777      SetEnabledStateOfControls();
     
    112112
    113113    private void FillListView() {
     114      string selectedName = null;
     115      if (listView.SelectedItems.Count == 1) selectedName = listView.SelectedItems[0].SubItems[0].Text;
     116
    114117      listView.Items.Clear();
    115118      listView.SmallImageList.Images.Clear();
    116119      if (Content != null) {
    117120        foreach (string key in Content.Parameters.Keys)
    118           CreateListViewItem(key, Content.Parameters[key], listView.Groups["parametersGroup"]);
     121          CreateListViewItem(key, Content.Parameters[key], listView.Groups["parametersGroup"], selectedName);
    119122        foreach (string key in Content.Results.Keys)
    120           CreateListViewItem(key, Content.Results[key], listView.Groups["resultsGroup"]);
     123          CreateListViewItem(key, Content.Results[key], listView.Groups["resultsGroup"], selectedName);
    121124        if (listView.Items.Count > 0) {
    122125          for (int i = 0; i < listView.Columns.Count; i++)
     
    126129    }
    127130
    128     private void CreateListViewItem(string name, IItem value, ListViewGroup group) {
     131    private void CreateListViewItem(string name, IItem value, ListViewGroup group, string selectedName) {
    129132      ListViewItem item = new ListViewItem(new string[] { name, value != null ? value.ToString() : "-" });
    130133      item.Tag = value;
     
    133136      item.ImageIndex = listView.SmallImageList.Images.Count - 1;
    134137      listView.Items.Add(item);
     138      if ((selectedName != null) && name.Equals(selectedName)) item.Selected = true;
    135139    }
    136140
    137141    private void listView_SelectedIndexChanged(object sender, EventArgs e) {
    138       if (listView.SelectedItems.Count == 1) {
    139         viewHost.ViewType = null;
     142      if (listView.SelectedItems.Count == 1)
    140143        viewHost.Content = (IContent)listView.SelectedItems[0].Tag;
    141       } else {
     144      else
    142145        viewHost.Content = null;
    143       }
    144146    }
    145147    private void listView_DoubleClick(object sender, EventArgs e) {
Note: See TracChangeset for help on using the changeset viewer.