zoukankan      html  css  js  c++  java
  • 设置DataGridView垂直滚动条

    1,

    #region 设置DataGridView垂直滚动条的值方法
            /// <summary>
            /// 设置DataGridView垂直滚动条的值
            /// </summary>
            /// <param name="dgv">要显示滚动条的DataGridView对象</param>
            /// <param name="scroll">滚动条对象</param>
            /// <param name="isScrollToBottom">是否滚动到底部</param>
            public static void SetScroll(DataGridView dgv, IcmsVScrollBar scroll, bool isScrollToBottom)
            {

                if (dgv == null
                    || scroll == null
                    || dgv.Rows.Count <= 0)
                    scroll.Visible = false;
                else
                {
                    int s = 0;
                    if (dgv.ColumnHeadersVisible)
                        s = dgv.ColumnHeadersHeight + (dgv.Rows.Count * dgv.Rows[0].Height);
                    else
                        s = dgv.Rows.Count * dgv.Rows[0].Height;

                    if (s > dgv.Height)
                    {
                        scroll.MaxValue = s + 10;
                        scroll.Visible = true;
                        scroll.AutoScrollPosition = new Point(0,
                    (dgv.FirstDisplayedScrollingRowIndex * dgv.Rows[0].Height) + dgv.ColumnHeadersHeight);

                        if (isScrollToBottom)
                        {
                            scroll.AutoScrollPosition = new Point(0, scroll.MaxValue);
                        }
                    }
                    else
                    {
                        scroll.Visible = false;
                    }
                }

            }
            #endregion

    2,

     

    #region 垂直滚动条拖动时执行方法
            /// <summary>
            /// 垂直滚动条拖动时执行
            /// </summary>
            /// <param name="dgv">要显示滚动条的DataGridView对象</param>
            /// <param name="scroll">滚动条对象</param>
            /// <param name="e">滚动事件参数</param>
            public static void ToScroll(DataGridView dgv, IcmsVScrollBar scroll, ScrollEventArgs e)
            {
                if (dgv == null
                    || scroll == null
                    || dgv.Rows.Count <= 0)
                    return;

                int ci = dgv.FirstDisplayedScrollingRowIndex;

                if (e.NewValue > e.OldValue)
                {
                    ci = ci + (e.NewValue - e.OldValue) / dgv.Rows[0].Height;
                    if (ci < dgv.RowCount)
                    {
                        dgv.FirstDisplayedScrollingRowIndex = ci;
                    }
                    else
                    {
                        dgv.FirstDisplayedScrollingRowIndex = dgv.RowCount - 1;
                    }
                }
                else if (e.NewValue < e.OldValue)
                {
                    ci = ci - (e.OldValue - e.NewValue) / dgv.Rows[0].Height;
                    if (ci >= 0)
                    {
                        dgv.FirstDisplayedScrollingRowIndex = ci;
                    }
                    else
                    {
                        dgv.FirstDisplayedScrollingRowIndex = 0;
                    }
                }
                scroll.AutoScrollPosition = new Point(0,
                    (dgv.FirstDisplayedScrollingRowIndex * dgv.Rows[0].Height) + dgv.ColumnHeadersHeight);

                Debug.WriteLine(scroll.AutoScrollPosition.ToString() + ", " + dgv.FirstDisplayedScrollingRowIndex.ToString());
            }
            #endregion

    3,DataGridView加载万数据后的事件:  DataBindingComplete.

     

  • 相关阅读:
    Solr的中英文分词实现
    乐观锁与悲观锁
    Keepalived + nginx实现高可用性和负载均衡
    Heartbeat实现集群高可用热备
    mongoDB 使用手册
    LVS+keepalived负载均衡
    keepalived工作原理和配置说明
    微信设置URL之WebApi方式
    RabbitMQ Windows下安装问题解决
    JSOM 中对各种字段操作
  • 原文地址:https://www.cnblogs.com/tangtang615/p/1402904.html
Copyright © 2011-2022 走看看