I am trying to control two DataGridView's with only one of the DataGridView vertical scroll bars being visible.
Asked
Active
Viewed 5,013 times
3 Answers
5
protected void grid1_Scroll(object sender, ScrollEventArgs e)
{
grid2.VerticallScrollBar.Value = e.NewValue;
}

Amiram Korach
- 13,056
- 3
- 28
- 30
1
If both DataGridView controls have equal number of rows, you can do the following. I am using this to compare two SQL resultsets side by side.
Set Scroll event handlers on both controls.
private void DataGridView1_Scroll(object sender, ScrollEventArgs e)
{
DataGridView2.FirstDisplayedScrollingRowIndex =
DataGridView1.FirstDisplayedScrollingRowIndex;
}
private void DataGridView2_Scroll(object sender, ScrollEventArgs e)
{
DataGridView1.FirstDisplayedScrollingRowIndex =
DataGridView2.FirstDisplayedScrollingRowIndex;
}

Dan S.
- 81
- 1
- 2
0
In Form.Load():
Grid1.Scroll += (s, ev) => Grid2.VerticalScrollBar.Value = Grid1.VerticalScrollBar.Value;
Edit: We can't assign Grid2.VerticalScrollingOffset as I had originally suggested, as it's a ReadOnly property.

MCattle
- 2,897
- 2
- 38
- 54
-
Yes, you're right. We'll have to use the VerticalScrollBar.Value instead, such as in the first answer. In this case, rather than fighting the UI, I'd also suggest looking at merging the two datasources into one, if that's possible for the original scenario. – MCattle Feb 07 '14 at 16:33