winform 多个datagridview 之间同步滚动

1.添加Scroll事件

2.注意需判断数据长度,避免溢出

private void dgYY_Scroll(object sender, ScrollEventArgs e)
        {
            if (this.dgFee.RowCount > 0)
            {
                dgFee.FirstDisplayedScrollingRowIndex = Math.Min(dgYY.FirstDisplayedScrollingRowIndex, this.dgFee.RowCount - 1);
                dgFee.HorizontalScrollingOffset = dgYY.HorizontalScrollingOffset;
            }
        }

        private void dgFee_Scroll(object sender, ScrollEventArgs e)
        {
            if (this.dgYY.RowCount > 0)
            {
                dgYY.FirstDisplayedScrollingRowIndex = Math.Min(dgFee.FirstDisplayedScrollingRowIndex, this.dgYY.RowCount - 1);
                dgYY.HorizontalScrollingOffset = dgFee.HorizontalScrollingOffset;
            }
        }

 

winform 多个datagridview 之间同步滚动

上一篇:C# 23种设计模式


下一篇:API接口认证&加密笔记