Scroll Bar inquiry

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
 
D

Dmitriy Lapshin [C# / .NET MVP]

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.
 
D

Dave Jackson

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

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top