By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,720 Members | 1,108 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,720 IT Pros & Developers. It's quick & easy.

Help with scrolling two DataGrids at the same time... CODE INCLUDED!

P: n/a
I'm having trouble scrolling some datagrids so they sync up...

I have two identical datagrids on a form, filled with eh same dataset. I want a user to be able to scroll on the datasets and the
other dataset then scrolls to the same place on the other dataset (bare with me). This is the code that I have so far...

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each acontrol As Control In DataGrid1.Controls
If acontrol.GetType() Is GetType(VScrollBar) Then
AddHandler CType(acontrol, VScrollBar).Scroll, AddressOf vertChange
Exit For
End If
End Sub

Private Sub vertChange(ByVal sender As Object, ByVal e As ScrollEventArgs)
Static Dim Value As Integer = 0

Dim hHScroll As IntPtr = FindWindowEx(DataGrid2.Handle, New IntPtr(0), "WindowsForms10.SCROLLBAR.app3", Nothing)
Dim hVScroll As IntPtr = FindWindowEx(DataGrid2.Handle, hHScroll, "WindowsForms10.SCROLLBAR.app3", Nothing)

If e.NewValue > Value Then
SendMessage(DataGrid2.Handle, MsgType.WM_VSCROLL, CType(MsgType.SB_PAGERIGHT, Integer), hVScroll.ToInt32)
SendMessage(DataGrid2.Handle, MsgType.WM_VSCROLL, CType(MsgType.SB_PAGELEFT, Integer), hVScroll.ToInt32)
End If

Value = e.NewValue

End Sub

I can get the datagrids to move together, but they don't always end up on the same line as each other. Anyone have any code to fix

Thanks a bunch!

Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.