zoukankan      html  css  js  c++  java
  • C# :DataGridView重新绑定时保持上次滚动位置

        DataGridView虽然有VerticalScrollBar属性, 但却是受保护的对象, 无法外部访问, 看了一下DataGridView的各项属性, 发现FirstDisplayedScrollingRowIndex就是滚动条的Value, DataGridView的行高乘以FirstDisplayedScrollingRowIndex就是客户区高度.

          以下是有关垂直滚动条的示例:

            int _ScrollValue = 0;

            private void dgvVehicles_Scroll(object sender, ScrollEventArgs e)
            {
                if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
                {
                    _ScrollValue = e.NewValue;
                }
            }

            private void BindData()
            {
                  // 设置数据源
                  ...
                  if (dgvVehicles.Rows.Count > _ScrollValue)
                      dgvVehicles.FirstDisplayedScrollingRowIndex = _ScrollValue;
            }

          另有一种做法是设置CurrentCell, 设置该值会使DataGridView跳到该单元格所在行. 方法就是遍历各行找出那个具有唯一性的Cell, 设为当前单元格.

  • 相关阅读:
    css3 实现水平或垂直布局
    css div 细边框
    css scroll bug
    F和弦大横按
    简单分析beyond作曲
    [编织消息框架][设计协议]优化long,int转换
    nginx 限制ip
    nginx注册成服务
    nginx 添加win 服务
    sqlserver 使用维护计划备份
  • 原文地址:https://www.cnblogs.com/Fooo/p/1619518.html
Copyright © 2011-2022 走看看