Beispiel #1
0
        public void AddRange(IEnumerable <T> tlist)
        {
            Boolean refreshDgv =
                (this.DataSourcePagered.Count > 0) &&
                (this.BindingSource.Position == this.DataSourcePagered.Count - 1) &&
                (this.DataSourcePagered[this.DataSourcePagered.Count - 1].Count < CountPerPage);

            lock (SyncRoot)
            {
                foreach (var item in tlist)
                {
                    SearchableSortableBindingList <T> list = null;
                    if (DataSourcePagered.Count > 0)
                    {
                        list = DataSourcePagered[DataSourcePagered.Count - 1];
                    }
                    if (list == null || list.Count == CountPerPage)
                    {
                        list = new SearchableSortableBindingList <T>();
                        DataSourcePagered.Add(list);
                    }
                    list.Add(item);
                }
            }

            if (refreshDgv)
            {
                BindDataGridView(DataSourcePagered[this.BindingSource.Position]);
            }

            OnCountChanged(EventArgs.Empty);
        }
Beispiel #2
0
        public void InitData(IEnumerable <T> data, Boolean gotoPageBefore)
        {
            this.Navigator.SuspendLayout();
            Int32 page = this.BindingSource.Position;

            lock (SyncRoot)
            {
                DataSourcePagered.Clear();
                SearchableSortableBindingList <T> list = new SearchableSortableBindingList <T>();
                foreach (var t in data)
                {
                    list.Add(t);
                    if (list.Count == CountPerPage)
                    {
                        DataSourcePagered.Add(list);
                        list = new SearchableSortableBindingList <T>();
                    }
                }

                if (list.Count > 0)
                {
                    DataSourcePagered.Add(list);
                }
            }

            this.Navigator.ResumeLayout();

            if (0 < DataSourcePagered.Count)
            {
                if (gotoPageBefore == true)
                {
                    if (page < 0)
                    {
                        page = 0;
                    }
                    else if (page >= DataSourcePagered.Count)
                    {
                        page = DataSourcePagered.Count - 1;
                    }

                    this.BindingSource.Position = page;
                }
                else
                {
                    page = 0;
                }
                BindDataGridView(DataSourcePagered[page]);
            }
            else
            {
                BindDataGridView(null);
            }

            OnCountChanged(EventArgs.Empty);
        }