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; } }