Free cookie consent management tool by TermsFeed Policy Generator

Changeset 190


Ignore:
Timestamp:
04/25/08 12:18:16 (17 years ago)
Author:
mkofler
Message:

Change to ItemDictionaryView: Removed automatic creation of dictionary by default constructor.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Data/ItemDictionaryView_T.cs

    r188 r190  
    99
    1010namespace HeuristicLab.Data {
    11   public partial class ItemDictionaryView<K, V> : ViewBase 
     11  public partial class ItemDictionaryView<K, V> : ViewBase
    1212    where K : IItem
    1313    where V : IItem {
     
    1515    private EditKeyValueDialog editKeyValueDialog;
    1616
    17     public ItemDictionary<K,V> ItemDictionary {
    18       get { return (ItemDictionary<K,V>) Item; }
     17    public ItemDictionary<K, V> ItemDictionary {
     18      get { return (ItemDictionary<K, V>) Item; }
    1919      set { base.Item = value; }
    2020    }
     
    2929    }
    3030
    31     public ItemDictionaryView() : this(new ItemDictionary<K,V>()) { }
    32 
    33     public ItemDictionaryView(ItemDictionary<K,V> dictionary) {
     31    public ItemDictionaryView() {
    3432      InitializeComponent();
    35       ItemDictionary = dictionary;
    3633      listView.View = View.Details;
    3734      listView.Columns[0].Text = "Key";
    3835      listView.Columns[1].Text = "Value";
     36    }
     37
     38    public ItemDictionaryView(ItemDictionary<K, V> dictionary)
     39      : this() {
     40      ItemDictionary = dictionary;
    3941      valueTypeTextBox.Text = typeof(V).ToString();
    40       keyTypeTextBox.Text = typeof(K).ToString(); 
     42      keyTypeTextBox.Text = typeof(K).ToString();
    4143    }
    4244
     
    133135      keyPanel.Enabled = false;
    134136      removeButton.Enabled = false;
    135 
    136       foreach (ListViewItem item in listView.Items) {
    137         ((IItem) item.SubItems[0]).Changed -= new EventHandler(Item_Changed);
    138         ((IItem) item.SubItems[1]).Changed -= new EventHandler(Item_Changed);
    139       }
    140       listView.Items.Clear();
    141       foreach (KeyValuePair<K, V> data in ItemDictionary) {
    142         ListViewItem item = CreateListViewItem(data.Key, data.Value);
    143         listView.Items.Add(item);
    144         data.Key.Changed += new EventHandler(Item_Changed);
    145         data.Value.Changed += new EventHandler(Item_Changed);
     137      if (ItemDictionary != null) {
     138        foreach (ListViewItem item in listView.Items) {
     139          ((IItem) item.SubItems[0]).Changed -= new EventHandler(Item_Changed);
     140          ((IItem) item.SubItems[1]).Changed -= new EventHandler(Item_Changed);
     141        }
     142        listView.Items.Clear();
     143        foreach (KeyValuePair<K, V> data in ItemDictionary) {
     144          ListViewItem item = CreateListViewItem(data.Key, data.Value);
     145          listView.Items.Add(item);
     146          data.Key.Changed += new EventHandler(Item_Changed);
     147          data.Value.Changed += new EventHandler(Item_Changed);
     148        }
     149        addButton.Enabled = true;
     150      } else {
     151        addButton.Enabled = false;
    146152      }
    147153    }
Note: See TracChangeset for help on using the changeset viewer.