private void UpdateFilteredData() { Dispatcher.Invoke(() => { FilteredData.Clear(); FilteredData.AddRange(Data.Where(proxy => !IsProxyFiltered(proxy))); using (PreventChangeSortingDirection preventor = new PreventChangeSortingDirection(DataGridControl)) { if (preventor.HasSorting) { SortFilteredData(preventor.SortMemberPath, preventor.SortDirection); } } UpdateStatusString(); }); }
private int GetInsertIndex(ObservableList <ProxyInfo> data, ProxyInfo proxy, PreventChangeSortingDirection preventor) { if (preventor.HasSorting) { int index = data.BinarySearch(proxy, new ProxyInfoComparer(preventor.SortMemberPath, preventor.SortDirection)); if (index < 0) { index = ~index; } if (index >= 0) { return(index); } } return(data.Count); }
public void Add(ProxyInfo proxy) { Dispatcher.BeginInvoke(new Action(() => { using (PreventChangeSortingDirection preventor = new PreventChangeSortingDirection(DataGridControl)) { Data.Add(proxy); if (!IsProxyFiltered(proxy)) { int index = GetInsertIndex(FilteredData, proxy, preventor); FilteredData.Insert(index, proxy); if (FilteredData.Count > 1) //If count is equal to one then PageData was updated already (on page changed event) { int page = (int)Math.Ceiling((double)(index + 1) / Context.Get <AllSettings>().PageSize); if (page <= Paging.Page && PageData.Count == Context.Get <AllSettings>().PageSize) { PageData.Remove(PageData.Last()); } if (page < Paging.Page) { PageData.Insert(0, FilteredData[(Paging.Page.Value - 1) * Context.Get <AllSettings>().PageSize]); } else if (page == Paging.Page) { PageData.Insert(index - (page - 1) * Context.Get <AllSettings>().PageSize, proxy); } } } UpdateStatusString(); } })); }