jzirbes527885

I have two dataGridView's that after filtering will always have the same number of rows and I would like to be able syncronize the scrolling, ie: scrolling either grid would scroll the other in sync. Is this possible

jzirbes



Re: Windows Forms Data Controls and Databinding Syncronize scrolling of 2 dataGridView's in C#

Gavin Jin - MSFT

I come across an article in msdn about How to Program Two List Boxes to Scroll Together,Hope this helps.




Re: Windows Forms Data Controls and Databinding Syncronize scrolling of 2 dataGridView's in C#

Zhi-Xin Ye - MSFT

You can use the FirstDisplayedScrollingRowIndex property.

namespace Sample4

{

public partial class DgvSyncScrollForm : Form

{

public DgvSyncScrollForm()

{

InitializeComponent();

}

private void DgvSyncScrollForm_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;

}

}

}






Re: Windows Forms Data Controls and Databinding Syncronize scrolling of 2 dataGridView's in C#

jzirbes

This is exactly what I needed, thanks very much!

I don't know how I missed that property when I was going through the list