今天在园子里看到一个人问,如何让两个DataGridView保持同步滚动?
一个最简单方法:) 不过大数据量时候闪啊闪。
private
void
dataGridView1_Scroll(
object
sender, ScrollEventArgs e)
{
dataGridView2.FirstDisplayedScrollingRowIndex = dataGridView1.FirstDisplayedScrollingRowIndex;
dataGridView2.HorizontalScrollingOffset = dataGridView1.HorizontalScrollingOffset;
}
private void dataGridView2_Scroll( object sender, ScrollEventArgs e)
{
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView2.FirstDisplayedScrollingRowIndex;
dataGridView1.HorizontalScrollingOffset = dataGridView2.HorizontalScrollingOffset;
}
{
dataGridView2.FirstDisplayedScrollingRowIndex = dataGridView1.FirstDisplayedScrollingRowIndex;
dataGridView2.HorizontalScrollingOffset = dataGridView1.HorizontalScrollingOffset;
}
private void dataGridView2_Scroll( object sender, ScrollEventArgs e)
{
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView2.FirstDisplayedScrollingRowIndex;
dataGridView1.HorizontalScrollingOffset = dataGridView2.HorizontalScrollingOffset;
}
简单吧。