Scroll Bar inquiry

  • Thread starter Thread starter Dave Jackson
  • Start date Start date
D

Dave Jackson

Hi All,

In my quest to have two windows scroll 'in sync', I've
turned to DataGrids which have accesible scroll bars. I've
created my own class that inherits from DataGrid, and
makes the scroll bars accesible:
public class MyDataGrid : System.Windows.Forms.DataGrid
{
public MyDataGrid()
{
InitializeComponent();
}
public ScrollBar HScrollBar
{
get
{
return HorizScrollBar;
}
}
}

Then, on my form I define a MyDataGrid, and add the
following to the Scroll event:

private void MyDataGrid1_Scroll(object sender,
System.EventArgs e)
{
MyDataGrid2.HScrollBar.Value =
MyDataGrid1.HScrollBar.Value;
}

This works great, the two Horizontal scroll bars move in
unison perfectly. The problem is that none of the text
inside the second MyDataGrid moves with the scroll bar, or
even moves at all. Is there anyway to force the data in
the MyDataGrid to move with the scroll bar? Otherwise
there isn't much point in scrolling =).

Thanks,
Dave
 
Dave,

I think it is much better to synchronize the grids by binding them to the
same datasource and specifying the same data member. Thus, the underlying
data binding mechanism should ensure the grids are in sync.
 
But my problem is that I'm comparing two seperate data
sources. And so when the user scrolls to looks at one
datagrid, the second datagrid should stay in sync so that
the user can compare the data.
-----Original Message-----
Dave,

I think it is much better to synchronize the grids by binding them to the
same datasource and specifying the same data member. Thus, the underlying
data binding mechanism should ensure the grids are in sync.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Dave Jackson said:
Hi All,

In my quest to have two windows scroll 'in sync', I've
turned to DataGrids which have accesible scroll bars. I've
created my own class that inherits from DataGrid, and
makes the scroll bars accesible:
public class MyDataGrid : System.Windows.Forms.DataGrid
{
public MyDataGrid()
{
InitializeComponent();
}
public ScrollBar HScrollBar
{
get
{
return HorizScrollBar;
}
}
}

Then, on my form I define a MyDataGrid, and add the
following to the Scroll event:

private void MyDataGrid1_Scroll(object sender,
System.EventArgs e)
{
MyDataGrid2.HScrollBar.Value =
MyDataGrid1.HScrollBar.Value;
}

This works great, the two Horizontal scroll bars move in
unison perfectly. The problem is that none of the text
inside the second MyDataGrid moves with the scroll bar, or
even moves at all. Is there anyway to force the data in
the MyDataGrid to move with the scroll bar? Otherwise
there isn't much point in scrolling =).

Thanks,
Dave

.
 
Back
Top