예제 #1
0
        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();
                }
            }));
        }