WPF 流加载

2021-06-21 10:05

阅读:251

标签:index   catch   change   vat   table   get   height   begin   ++   

        /// 
        /// datatable分页
        /// 
        /// 源datatable
        /// 第几页
        /// 每页记录数
        /// 
        public DataTable GetPagedTable(DataTable dt, int PageIndex, int PageSize)
        {
            if (PageIndex == 0)
                return dt;

            DataTable newdt = dt.Copy();
            newdt.Clear();

            int rowbegin = (PageIndex - 1) * PageSize;
            int rowend = PageIndex * PageSize;

            if (rowbegin >= dt.Rows.Count)
                return newdt;

            if (rowend > dt.Rows.Count)
                rowend = dt.Rows.Count;
            for (int i = rowbegin; i 1; i++)
            {
                DataRow newdr = newdt.NewRow();
                DataRow dr = dt.Rows[i];
                foreach (DataColumn column in dt.Columns)
                {
                    newdr[column.ColumnName] = dr[column.ColumnName];
                }
                newdt.Rows.Add(newdr);
            }
            return newdt;
        }

 

private void sv_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            try
            {
                ScrollViewer sv = e.OriginalSource as ScrollViewer;
                if (sv != null && e.VerticalChange != 0)
                {
                    if (sv.VerticalOffset == sv.ExtentHeight - sv.ViewportHeight)//到底
                    {
                        //TODO:加载下条数据
                        if (SteamDataTable != null)
                        {
                            Pgindex++;
                            AddData(GetPagedTable(SteamDataTable, Pgindex, PageSize));
                        }
                    }
                }
            }
            catch
            { }
        }

 

WPF 流加载

标签:index   catch   change   vat   table   get   height   begin   ++   

原文地址:https://www.cnblogs.com/SeNaiTes/p/10239847.html


评论


亲,登录后才可以留言!