You can handle the scroll event to set the FirstDisplayRowIndex property to sync the datagridviews. Below is my sample
Sample4
public partial class DgvSyncScroll : Form
{
public DgvSyncScroll()
{
InitializeComponent();
}
private void DgvSyncScroll_Load(object sender, EventArgs e)
{
DataTable dt2 = new DataTable();
dt2.Columns.Add("OrderId", typeof(int));
dt2.Columns.Add("ProdID", typeof(int));
dt2.Columns.Add("Quantity", typeof(int));
for (int j = 0; j < 22; j++)
{
dt2.Rows.Add(j, j + 1, j + 2);
}
this.dataGridView1.DataSource = dt2;
this.dataGridView2.DataSource = dt2;
this.dataGridView1.Scroll += new ScrollEventHandler(dataGridView1_Scroll);
this.dataGridView2.Scroll += new ScrollEventHandler(dataGridView2_Scroll);
}
void dataGridView2_Scroll(object sender, ScrollEventArgs e)
{
this.dataGridView1.FirstDisplayedScrollingRowIndex = this.dataGridView2.FirstDisplayedScrollingRowIndex;
}
void dataGridView1_Scroll(object sender, ScrollEventArgs e)
{
this.dataGridView2.FirstDisplayedScrollingRowIndex = this.dataGridView1.FirstDisplayedScrollingRowIndex;
}
}