#if FRAMEWORK20 using System; using System.Collections.Generic; using System.Text; using System.Collections.ObjectModel; using System.ComponentModel; namespace DevComponents.DotNetBar { public class PropertySettingsCollection : Collection { #region Constructor /// /// Initializes a new instance of the PropertyGridInfoCollection class. /// /// public PropertySettingsCollection(AdvPropertyGrid owner) { _Owner = owner; } #endregion #region Internal Implementation protected override void InsertItem(int index, PropertySettings item) { base.InsertItem(index, item); OnAfterItemAdded(item); } private void OnAfterItemAdded(PropertySettings item) { _Owner.PropertySettingsItemAdded(item); } protected override void ClearItems() { PropertySettings[] items = new PropertySettings[this.Count]; this.CopyTo(items, 0); base.ClearItems(); foreach (PropertySettings item in items) { OnAfterItemRemoved(item); } } protected override void RemoveItem(int index) { PropertySettings info = this[index]; base.RemoveItem(index); OnAfterItemRemoved(info); } private void OnAfterItemRemoved(PropertySettings info) { _Owner.PropertySettingsItemRemoved(info); } protected override void SetItem(int index, PropertySettings item) { PropertySettings oldItem = this[index]; base.SetItem(index, item); OnAfterItemRemoved(oldItem); OnAfterItemAdded(item); } /// /// Gets property info object based on property name. /// /// Property name. /// PropertyGridInfo instance or null if it cannot be found. public virtual PropertySettings this[string propertyName] { get { foreach (PropertySettings item in this) { if (item.PropertyName == propertyName) return item; } return null; } } private Dictionary _DictionaryByDescriptor = new Dictionary(); /// /// Gets property info object based on property descriptor. /// /// Property descriptor. /// PropertyGridInfo instance or null if it cannot be found. public virtual PropertySettings this[PropertyDescriptor propertyDescriptor] { get { foreach (PropertySettings item in this) { if (item.PropertyDescriptor.Equals(propertyDescriptor)) return item; } return null; } } /// /// Returns property setting based on property descriptor or name if property descriptor is not set on property settings /// Property descriptor takes precedence. /// /// Property descriptor to look for. /// Property Name to look for. /// Property settings instance or null public virtual PropertySettings this[PropertyDescriptor propertyDescriptor, string propertyName] { get { PropertySettings settingByName = null; foreach (PropertySettings item in this) { if (item.PropertyDescriptor != null && item.PropertyDescriptor.Equals(propertyDescriptor)) return item; else if (item.PropertyName == propertyName) settingByName = item; } return settingByName; } } private AdvPropertyGrid _Owner = null; /// /// Gets the owner of the collection. /// public AdvPropertyGrid Owner { get { return _Owner; } } #endregion } } #endif