DataGridView控件判断滚动条是否滚动到当前已加载的数据行底部

private void dgvLoad_Scroll(object sender, ScrollEventArgs e)
        {
            if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
            {
                if (e.NewValue + dgvLoad.DisplayedRowCount(false) == dgvLoad.Rows.Count)
                {
                
                   MsgShow.Warning(string.Format("NewValue:{0}--OldValue:{1}--DisplayedRowCount:{2}", e.NewValue, e.OldValue,dgvLoad.DisplayedRowCount(false)));
                   MsgShow.Warning("到底了,可以加载新数据了!");
                    //这里面写加载数据的相关操作逻辑
                }
            }
        }
        /// <summary>
        /// 注册滚动条滚功到末尾时的处理事件
         /// </summary>
        /// <param name="grid"></param>
        /// <param name="onScrollToEnd"></param>
        public static void RegistScrollToEndEvent(this DataGridView grid, EventHandler onScrollToEnd)
        {
            grid.Scroll += new ScrollEventHandler((sender, e) =>
            {
                if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
                {
                    if (e.NewValue + grid.DisplayedRowCount(false) == grid.Rows.Count)
                    {
                        if (onScrollToEnd != null)
                        {
                            onScrollToEnd(grid, null);
                        }
                    }
                }
            });
        }
dgvLoad.RegistScrollToEndEvent(dataGrid_OnScrollToEnd);

void dataGrid_OnScrollToEnd(object sender, EventArgs e)
        {
            MessageBox.Show("load data!");
        }
posted @ 2015-06-03 20:08  ______Smileヾ淡莣丶  阅读(351)  评论(0编辑  收藏  举报