public void ApplySort(System.ComponentModel.ListSortDescriptionCollection sorts) { _descrips = sorts; if (sorts == null || sorts.Count < 1) { if (_filter == null) { _filterIds.Clear(); } else { _filterIds.Sort(); } } else { if (!_filterIds.Any() && _filter == null) { _filterIds.AddRange(Enumerable.Range(0, _list.Count)); } _filterIds.Sort((x, y) => CompareProp((T)_list[x], (T)_list[y])); } ResetBindings(); }
public void ApplySortMultipleProps() { ViewFactory<SimpleClass> factory = ViewFactory<SimpleClass>.IList(); IList<SimpleClass> list = factory.List; ObjectListView<SimpleClass> view = factory.View; list.Add(new SimpleClass(4, "aaa", new DateTime(1930, 5, 5))); list.Add(new SimpleClass(2, "qqq", new DateTime(1950, 5, 5))); list.Add(new SimpleClass(1, "zzz", new DateTime(1980, 5, 5))); list.Add(new SimpleClass(2, "mmm", new DateTime(1960, 5, 5))); list.Add(new SimpleClass(3, "bbb", new DateTime(1940, 5, 5))); list.Add(new SimpleClass(2, "mmm", new DateTime(1970, 5, 5))); PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(SimpleClass)); ListSortDescriptionCollection sorts = new ListSortDescriptionCollection(new ListSortDescription[] { new ListSortDescription(props["IntegerValue"], ListSortDirection.Ascending), new ListSortDescription(props["StringValue"], ListSortDirection.Descending), new ListSortDescription(props["DateTimeValue"], ListSortDirection.Ascending) }); view.ApplySort(sorts); IEnumerator<SimpleClass> pos = view.GetEnumerator(); pos.MoveNext(); SimpleClass val = pos.Current; Assert.IsNotNull(val); Assert.AreEqual(1, val.IntegerValue); pos.MoveNext(); val = pos.Current; Assert.IsNotNull(val); Assert.AreEqual(2, val.IntegerValue); Assert.AreEqual("qqq", val.StringValue); Assert.AreEqual(new DateTime(1950, 5, 5), val.DateTimeValue); pos.MoveNext(); val = pos.Current; Assert.IsNotNull(val); Assert.AreEqual(2, val.IntegerValue); Assert.AreEqual("mmm", val.StringValue); Assert.AreEqual(new DateTime(1960, 5, 5), val.DateTimeValue); pos.MoveNext(); val = pos.Current; Assert.IsNotNull(val); Assert.AreEqual(2, val.IntegerValue); Assert.AreEqual("mmm", val.StringValue); Assert.AreEqual(new DateTime(1970, 5, 5), val.DateTimeValue); pos.MoveNext(); val = pos.Current; Assert.IsNotNull(val); Assert.AreEqual(3, val.IntegerValue); pos.MoveNext(); val = pos.Current; Assert.IsNotNull(val); Assert.AreEqual(4, val.IntegerValue); }
public override void ApplySort(System.ComponentModel.ListSortDescriptionCollection sorts) { List <T> sortableList = mList as List <T>; if (sortableList == null) { throw new DevAgeApplicationException("Sort not supported, the list must be an instance of List<T>."); } sortableList.Sort( delegate(T x, T y) { foreach (System.ComponentModel.ListSortDescription sort in sorts) { IComparable valx = sort.PropertyDescriptor.GetValue(x) as IComparable; IComparable valy = sort.PropertyDescriptor.GetValue(y) as IComparable; //Swap the objects if the sort direction is Descending if (sort.SortDirection == ListSortDirection.Descending) { IComparable tmp = valx; valx = valy; valy = tmp; } if (valx != null && valy != null) { int result = valx.CompareTo(valy); if (result != 0) { return(result); } } else if (valx != null) { return(1); } else { return(-1); } } return(0); } ); OnListChanged(new System.ComponentModel.ListChangedEventArgs(System.ComponentModel.ListChangedType.Reset, -1)); }
public void Can_sort_the_list() { Assert.AreEqual(_theUnit.Items[0].Position, "2"); FakeObject fakeObject = new FakeObject("", "", ""); PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(fakeObject); PropertyDescriptor sortProperty = properties.Find("Position", false); List<ListSortDescription> descriptions = new List<ListSortDescription>(); descriptions.Add(new ListSortDescription(sortProperty, new ListSortDirection())); ListSortDescriptionCollection sorts = new ListSortDescriptionCollection(descriptions.ToArray()); _theUnit.ApplySort(sorts); Assert.AreEqual(_theUnit.Items[0].Position, "1"); }
public Main() { PropertyDescriptorCollection props; InitializeComponent(); // make up the sort rules for the lists props = TypeDescriptor.GetProperties(typeof(InitiativeTableEntry), new Attribute[] { new BrowsableAttribute(true) }); m_sorts = new ListSortDescriptionCollection(new ListSortDescription[] { new ListSortDescription(props["Initiative"], ListSortDirection.Descending), new ListSortDescription(props["InitiativeBonus"], ListSortDirection.Descending), new ListSortDescription(props["Tiebreaker"], ListSortDirection.Descending), new ListSortDescription(props["IsCombatant"], ListSortDirection.Descending), }); this.Load += new EventHandler(Main_Load); this.FormClosed += new FormClosedEventHandler(Main_FormClosed); }
public void ApplySort(System.ComponentModel.ListSortDescriptionCollection sorts) { var args = new SortChangingEventArgs() { Sort = sorts, Handled = false }; OnSortChanging(args); if (args.Handled) { sorts = args.Sort; } _descrips = sorts; if (sorts == null || sorts.Count < 1) { if (_filter == null) { _filterIds.Clear(); } else { _filterIds.Sort(); } } else { if (!_filterIds.Any() && _filter == null) { _filterIds.AddRange(Enumerable.Range(0, _list.Count)); } _filterIds.Sort((x, y) => CompareProp((T)_list[x], (T)_list[y])); } ResetBindings(); }
public void ApplySort(ListSortDescriptionCollection i_Sorts) { throw new NotImplementedException(); }
public void SortDescriptionsSortedMultipleProps() { ViewFactory<SimpleClass> factory = ViewFactory<SimpleClass>.IList(); IList<SimpleClass> list = factory.List; ObjectListView<SimpleClass> view = factory.View; list.Add(new SimpleClass(1, "aaa", DateTime.Now)); list.Add(new SimpleClass(1, "bbb", new DateTime(1950, 1, 1))); list.Add(new SimpleClass(3, "ccc", DateTime.Now)); list.Add(new SimpleClass(4, "ddd", DateTime.Now)); list.Add(new SimpleClass(1, "eee", DateTime.Now)); list.Add(new SimpleClass(1, "bbb", new DateTime(1960, 1, 1))); PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(SimpleClass)); PropertyDescriptor stringProp = props["StringValue"]; PropertyDescriptor dateProp = props["DateTimeValue"]; ListSortDescriptionCollection sorts = new ListSortDescriptionCollection(new ListSortDescription[] { new ListSortDescription(stringProp, ListSortDirection.Descending), new ListSortDescription(dateProp, ListSortDirection.Ascending)}); view.ApplySort(sorts); Assert.IsNotNull(view.SortDescriptions); Assert.AreEqual(2, view.SortDescriptions.Count); Assert.AreEqual(stringProp, view.SortDescriptions[0].PropertyDescriptor); Assert.AreEqual(ListSortDirection.Descending, view.SortDescriptions[0].SortDirection); Assert.AreEqual(dateProp, view.SortDescriptions[1].PropertyDescriptor); Assert.AreEqual(ListSortDirection.Ascending, view.SortDescriptions[1].SortDirection); }
public void SortDescriptionsRemoveSort() { ViewFactory<SimpleClass> factory = ViewFactory<SimpleClass>.IList(); IList<SimpleClass> list = factory.List; ObjectListView<SimpleClass> view = factory.View; DateTime now = DateTime.Now; list.Add(new SimpleClass(1, "aaa", now)); list.Add(new SimpleClass(1, "bbb", new DateTime(1950, 1, 1))); list.Add(new SimpleClass(3, "ccc", now)); list.Add(new SimpleClass(3, "ddd", now)); list.Add(new SimpleClass(1, "eee", now)); list.Add(new SimpleClass(1, "bbb", new DateTime(1960, 1, 1))); PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(SimpleClass)); PropertyDescriptor intProp = props["IntegerValue"]; ListSortDescriptionCollection sorts = new ListSortDescriptionCollection(new ListSortDescription[] { new ListSortDescription(intProp, ListSortDirection.Ascending)}); view.ApplySort(sorts); view.RemoveSort(); Assert.IsNotNull(view.SortDescriptions); Assert.AreEqual(0, view.SortDescriptions.Count); }
public void ApplySort(ListSortDescriptionCollection sorts) { BindingListImpl.ApplySort(sorts); }
public virtual void ApplySort(ListSortDescriptionCollection sorts);
public QueryParameters SetSortDescriptions(ListSortDescriptionCollection value) { return new QueryParameters(this) {SortDescriptions = value}; }
public SortListPropertyComparer(ListSortDescriptionCollection sorts) { _sorts = sorts; }
private IComparer GetSortComparer(ListSortDescriptionCollection sortDescriptions) { bool needSubstitution = false; if (_sortSubstitutions.Count > 0) { foreach (ListSortDescription sortDescription in sortDescriptions) { if (_sortSubstitutions.ContainsKey(sortDescription.PropertyDescriptor.Name)) { needSubstitution = true; break; } } if (needSubstitution) { ListSortDescription[] sorts = new ListSortDescription[sortDescriptions.Count]; sortDescriptions.CopyTo(sorts, 0); for (int i = 0; i < sorts.Length; i++) if (_sortSubstitutions.ContainsKey(sorts[i].PropertyDescriptor.Name)) sorts[i] = new ListSortDescription(((SortSubstitutionPair)_sortSubstitutions[sorts[i].PropertyDescriptor.Name]).Substitute, sorts[i].SortDirection); sortDescriptions = new ListSortDescriptionCollection(sorts); } } return new SortListPropertyComparer(sortDescriptions); }
public void ApplySort(ListSortDescriptionCollection sorts) { _sortDescriptions = sorts; _isSorted = true; _sortProperty = null; ApplySort(GetSortComparer(sorts)); if (_list.Count > 0) OnReset(); }
void IBindingListView.ApplySort(ListSortDescriptionCollection sorts) { Debugger.Break(); throw new NotImplementedException(); }
public void ApplySort(ListSortDescriptionCollection sorts) { _sortDescriptions = sorts; _isSorted = true; _sortProperty = null; ApplySort(GetSortComparer(sorts)); if (_list.Count > 0) OnListChanged(new EditableListChangedEventArgs(ListChangedType.Reset)); }
void IBindingListView.ApplySort(ListSortDescriptionCollection sorts) { sort.Clear(); foreach(ListSortDescription lsd in sorts) { if(lsd == null) continue; sort.Add(lsd); } Sort(); }
/// <summary> /// Applies a series of sort properties and directions to this ObjectListView. /// </summary> /// <param name="sorts">The sort directions and properties.</param> void IBindingListView.ApplySort(System.ComponentModel.ListSortDescriptionCollection sorts) { _sorts = sorts; if (_sortIndex != null) { for (int i = 0; i < _sortIndex.Count; i++) { _sortIndex[i].PropertyChanged -= new PropertyChangedEventHandler(ObjectView_PropertyChanged); } } if (_list == null) { _sortIndex = new List<ObjectView>(); } else { _sortIndex = new List<ObjectView>(_list.Count); for (int i = 0; i < _list.Count; i++) { ObjectView item = ObjectView.NewObjectView(this, _list[i], i); item.PropertyChanged += new PropertyChangedEventHandler(ObjectView_PropertyChanged); item.ApplyFilter(_filteredView); this.InsertInOrder(item, 0, _sortIndex.Count); } } this.OnListChanged(ListChangedType.Reset, -1); }
public virtual void ApplySort(ListSortDescriptionCollection sorts) { IBindingListView iblw = List as IBindingListView; if (iblw != null) { iblw.ApplySort(sorts); } else { throw new NotSupportedException(SR.GetString(SR.OperationRequiresIBindingListView)); } }
public QueryParameters(ViewInfo viewInfo, RowFilter rowFilter, ListSortDescriptionCollection sortDescriptions) { ViewInfo = viewInfo; RowFilter = rowFilter; SortDescriptions = sortDescriptions; }
/// <summary> /// Sorts the view based on a <see cref="T:System.ComponentModel.PropertyDescriptor"></see> and a <see cref="T:System.ComponentModel.ListSortDirection"></see>. /// </summary> /// <param name="property">The <see cref="T:System.ComponentModel.PropertyDescriptor"></see> to sort by.</param> /// <param name="direction">One of the <see cref="T:System.ComponentModel.ListSortDirection"></see> values.</param> public void ApplySort(PropertyDescriptor property, ListSortDirection direction) { Lock(); try { ListSortDescriptionCollection proposed; if (property == null) proposed = new ListSortDescriptionCollection(); else { ValidateProperty(property); ListSortDescription[] props = new ListSortDescription[] { new ListSortDescription(property, direction) }; proposed = new ListSortDescriptionCollection(props); } this.SortProperties = proposed; } finally { Unlock(); } RaiseEvents(); }
//------------------------------------------------------------------------------------- #region IBindingListView Members void IBindingListView.ApplySort(ListSortDescriptionCollection sorts) { if(_sorts == null) _sorts = new List<ListSortDescription>(); else _sorts.Clear(); foreach(ListSortDescription lsd in sorts) { if(lsd == null) continue; _sorts.Add(lsd); } ApplySort(DefaultSorter); }
public void ApplySort(ListSortDescriptionCollection sorts) { throw new Exception("The method or operation is not implemented."); }
public virtual void ApplySort (ListSortDescriptionCollection sorts) { if (!(list is IBindingListView)) throw new NotSupportedException ("This operation requires an IBindingListView."); IBindingListView iblist_view = (IBindingListView)list; iblist_view.ApplySort (sorts); }
public virtual void ApplySort(ListSortDescriptionCollection sorts) { IBindingListView list = this.List as IBindingListView; if (list == null) { throw new NotSupportedException(System.Windows.Forms.SR.GetString("OperationRequiresIBindingListView")); } list.ApplySort(sorts); }
/////////////////////////////////////////////////////////////////////////////// // // Methods // /////////////////////////////////////////////////////////////////////////////// /* CUT: // // AutoSetDataMember() // // Used when data source changes. If data member is not set, and the data source // is a list of lists, arbitrarily point the data member at one of these lists. // private void AutoSetDataMember() { // Data member already assigned! if (!String.IsNullOrEmpty(this.dataMember)) { return; } // Get the list of lists IListSource listSource = this.dataSource as IListSource; // Not a list of lists! if (listSource == null || !listSource.ContainsListCollection) { return; } // Get properties of data source PropertyDescriptorCollection props = ListBindingHelper.GetListItemProperties(listSource); // Walk properties of data source, looking for one that returns IList (but ignoring ones that return Array) for (int i = 0; i < props.Count; ++i) { PropertyDescriptor prop = props[i]; if (typeof(IList).IsAssignableFrom(prop.PropertyType) && !typeof(Array).IsAssignableFrom(prop.PropertyType)) { // Bingo - got one! this.dataMember = prop.Name; OnDataMemberChanged(EventArgs.Empty); break; } } } */ private static string BuildSortString(ListSortDescriptionCollection sortsColln) { if (sortsColln == null) { return String.Empty; } StringBuilder sb = new StringBuilder(sortsColln.Count); for (int i = 0; i < sortsColln.Count; ++i) { sb.Append(sortsColln[i].PropertyDescriptor.Name + ((sortsColln[i].SortDirection == ListSortDirection.Ascending) ? " ASC" : " DESC") + ((i < sortsColln.Count - 1) ? "," : String.Empty)); } return sb.ToString(); }
public void SortedEvent() { ViewFactory factory = ViewFactory.IListSimpleItems(); ObjectListView view = factory.View; IList list = factory.List; DateTime now = DateTime.Now; list.Add(new SimpleClass(1, "aaa", now)); list.Add(new SimpleClass(1, "bbb", new DateTime(1950, 1, 1))); list.Add(new SimpleClass(3, "ccc", now)); list.Add(new SimpleClass(3, "ddd", now)); list.Add(new SimpleClass(1, "eee", now)); list.Add(new SimpleClass(1, "bbb", new DateTime(1960, 1, 1))); view.ItemType = typeof(SimpleClass); PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(SimpleClass)); PropertyDescriptor intProp = props["IntegerValue"]; ListSortDescriptionCollection sorts = new ListSortDescriptionCollection(new ListSortDescription[] { new ListSortDescription(intProp, ListSortDirection.Ascending)}); Assert.AreEqual(0, factory.SortedCount); view.ApplySort(sorts); Assert.AreEqual(1, factory.SortedCount); }
/// <summary> /// Sorts the view of the underlying list based on the given <see cref="T:System.ComponentModel.ListSortDescriptionCollection"></see>. /// </summary> /// <param name="sorts">The <see cref="T:System.ComponentModel.ListSortDescriptionCollection"></see> containing the sorts to apply to the view.</param> public void ApplySort(ListSortDescriptionCollection sorts) { Lock(); try { ListSortDescriptionCollection proposed; if (sorts == null) proposed = new ListSortDescriptionCollection(); else { foreach (ListSortDescription desc in sorts) ValidateProperty(desc.PropertyDescriptor); ListSortDescription[] props = new ListSortDescription[sorts.Count]; sorts.CopyTo(props, 0); proposed = new ListSortDescriptionCollection(props); } this.SortProperties = proposed; } finally { Unlock(); } RaiseEvents(); }
public void SortGetRemoveSort() { ViewFactory factory = ViewFactory.IListSimpleItems(); ObjectListView view = factory.View; IList list = factory.List; view.ItemType = typeof(SimpleClass); list.Add(new SimpleClass(4, "aaa", new DateTime(1930, 5, 5))); list.Add(new SimpleClass(2, "qqq", new DateTime(1950, 5, 5))); list.Add(new SimpleClass(1, "zzz", new DateTime(1980, 5, 5))); list.Add(new SimpleClass(2, "mmm", new DateTime(1960, 5, 5))); list.Add(new SimpleClass(3, "bbb", new DateTime(1940, 5, 5))); list.Add(new SimpleClass(2, "mmm", new DateTime(1970, 5, 5))); PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(SimpleClass)); ListSortDescriptionCollection sorts = new ListSortDescriptionCollection(new ListSortDescription[] { new ListSortDescription(props["IntegerValue"], ListSortDirection.Ascending), new ListSortDescription(props["StringValue"], ListSortDirection.Descending), new ListSortDescription(props["DateTimeValue"], ListSortDirection.Ascending) }); view.ApplySort(sorts); view.RemoveSort(); Assert.AreEqual("", view.Sort); }
/// <summary> /// Sort the list /// </summary> /// <param name="sorts"></param> public abstract void ApplySort(System.ComponentModel.ListSortDescriptionCollection sorts);
public void RemoveSortedIBindingList() { ViewFactory factory = ViewFactory.IBindingListSimpleItems(); ObjectListView view = factory.View; IList list = factory.List; DateTime now = DateTime.Now; list.Add(new SimpleClass(5, "aaa", now)); list.Add(new SimpleClass(4, "bbb", new DateTime(1950, 1, 1))); list.Add(new SimpleClass(3, "ccc", now)); list.Add(new SimpleClass(3, "ddd", now)); list.Add(new SimpleClass(1, "eee", now)); list.Add(new SimpleClass(2, "bbb", new DateTime(1960, 1, 1))); view.ItemType = typeof(SimpleClass); PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(SimpleClass)); PropertyDescriptor intProp = props["IntegerValue"]; ListSortDescriptionCollection sorts = new ListSortDescriptionCollection(new ListSortDescription[] { new ListSortDescription(intProp, ListSortDirection.Ascending)}); view.ApplySort(sorts); factory.ClearEventCounts(); view.RemoveAt(3); view.RemoveAt(2); Assert.AreEqual(4, view.Count); Assert.AreEqual(1, ((SimpleClass)view[0]).IntegerValue); Assert.AreEqual(2, ((SimpleClass)view[1]).IntegerValue); Assert.AreEqual(4, ((SimpleClass)view[2]).IntegerValue); Assert.AreEqual(5, ((SimpleClass)view[3]).IntegerValue); Assert.AreEqual(2, factory.ListChangedDeletedCount); Assert.AreEqual(0, factory.ListChangedResetCount); Assert.AreEqual(0, factory.SortedCount); }
void IBindingListView.ApplySort(ListSortDescriptionCollection sorts) { _list.ApplySort(sorts); }
public void UsePropertyComparerMultipleColumnsInMultiColumnSort() { ViewFactory factory = ViewFactory.IBindingListSimpleItems(); ObjectListView view = factory.View; IList list = factory.List; DateTime now = DateTime.Now; list.Add(new SimpleClass(1, "a", now)); list.Add(new SimpleClass(1, "bbb", now)); list.Add(new SimpleClass(1, "aaaa", now)); list.Add(new SimpleClass(1, "aa", new DateTime(1989, 7, 22))); list.Add(new SimpleClass(1, "aa", new DateTime(1991, 3, 5))); view.PropertyComparers["StringValue"] = new StringLengthComparer(); view.PropertyComparers["DateTimeValue"] = new DateTimeDayComparer(); PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(SimpleClass)); ListSortDescriptionCollection sorts = new ListSortDescriptionCollection(new ListSortDescription[] { new ListSortDescription(props["StringValue"], ListSortDirection.Descending), new ListSortDescription(props["DateTimeValue"], ListSortDirection.Ascending) }); view.ApplySort(sorts); Assert.AreEqual("aaaa", ((SimpleClass)view[0]).StringValue); Assert.AreEqual("bbb", ((SimpleClass)view[1]).StringValue); Assert.AreEqual(new DateTime(1991, 3, 5), ((SimpleClass)view[2]).DateTimeValue); Assert.AreEqual(new DateTime(1989, 7, 22), ((SimpleClass)view[3]).DateTimeValue); Assert.AreEqual("a", ((SimpleClass)view[4]).StringValue); }