/// <summary> /// When the sort or filter changes, creates or destroys the view /// as needed. /// /// This should only be called if a sort or filter is applied. /// /// BUGBUG: what happens if there was a sort or filter, but they are being removed? /// </summary> void UpdateView() { if (view != null && model != null) { var temp = new DataStoreVirtualCollection <object>(model); // filter if needed var viewItems = (Filter != null) ? temp.Where(Filter).ToList() : temp.ToList(); // sort if needed if (this.comparer != null) { viewItems.Sort(this.comparer); } // Clear and re-add the list view.Clear(); view.AddRange(viewItems); // If a sort or filter is specified, create a dictionary // of the item indices. This materializes a list of all the // objects. // If no sort or filter is specified, this overhead is avoided. viewToModel = null; modelToView = null; if (HasSortOrFilter) { viewToModel = new List <int>(); modelToView = new Dictionary <int, int>(); // Create a temporary dictionary of model items var modelIndexes = new Dictionary <object, int>(); for (var i = 0; i < temp.Count; ++i) { var o = temp[i]; if (o != null) { modelIndexes[o] = i; } } var viewIndex = 0; foreach (var o in viewItems) { var modelIndex = -1; if (o != null && modelIndexes.TryGetValue(o, out modelIndex)) { modelToView[modelIndex] = viewIndex; } viewToModel.Add(modelIndex); // always add to viewToModel because the number of items must match those in viewItems viewIndex++; } } } }
public DataStoreEnumerator(DataStoreVirtualCollection <T> collection) { this.collection = collection; this.cursor = -1; }