/// <summary> /// Implementation of <see cref="System.ComponentModel.IBindingList.ApplySort"/>. /// </summary> public void ApplySort(PropertyDescriptor property, ListSortDirection direction) { isSorted = true; sortProperty = property; listSortDirection = direction; ArrayList a = new ArrayList(); if (property is CaptionPropertyDescriptor) { CaptionPropertyDescriptor prop = property as CaptionPropertyDescriptor; if (prop.AllowSort) { InnerList.Sort(new ObjectPropertyComparer(prop.OriginalName)); if (direction == ListSortDirection.Descending) { InnerList.Reverse(); } } } else { InnerList.Sort(new ObjectPropertyComparer(property.Name)); if (direction == ListSortDirection.Descending) { InnerList.Reverse(); } } }
/// <summary> /// Implementation of <see cref="System.ComponentModel.ITypedList.GetItemProperties"/>. /// </summary> /// <remarks> /// For each property method of the type contained in the list, a <c>PropertyDescriptor</c> /// will be created. If a property is flagged <i>not visible</i>, it will be omitted. /// The <c>TypedArrayList</c> uses a custom implementation of the PropertyDescriptor, /// <see cref="CaptionPropertyDescriptor"/>, to support interpreting attributes. /// </remarks> public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors) { ArrayList descriptors = new ArrayList(); foreach (PropertyInfo propertyInfo in properties) { object[] attributes = propertyInfo.GetCustomAttributes(typeof(VisibleAttribute), true); CaptionPropertyDescriptor cpd = null; if (attributes.Length == 1) { VisibleAttribute visible = (VisibleAttribute)attributes[0]; if (visible.Value) { cpd = new CaptionPropertyDescriptor(propertyInfo.Name, propertyInfo); } } else { cpd = new CaptionPropertyDescriptor(propertyInfo.Name, propertyInfo); } if (cpd != null && cpd.OriginalDescriptor != null) { descriptors.Add(cpd); } } PropertyDescriptor[] propertyDescriptors = new PropertyDescriptor[descriptors.Count]; descriptors.CopyTo(propertyDescriptors, 0); return(new PropertyDescriptorCollection(propertyDescriptors)); }