By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,214 Members | 2,099 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

Synchronised Listviews

P: 1
Searched everywhere for a way to synchronise the scrolling of 2 listviews, found a few that were too big and complicated or did not work properly, so made my own by trickery

You need 2 or more listviews and a vertical scroller, get them from the components/microsoft common tools 6
put the first listview where you want it and the second overlapping the first so that it hides the built in vertical scrollbar
put the scrollbar on top of the last listview so that it hides the built in scrollbar
use the scroller (vscroll1) scroll to get the values and the selecteditem of the listviews to set the position

Dim Addit As Object
Dim a, b As String
Dim z, y As Integer

Private Sub Form_Load()
Form1.Visible = True
With ListView1.ColumnHeaders.Add
.Width = (ListView1.Width - 300)
.Text = "Test"
End With
With ListView2.ColumnHeaders.Add
.Width = (ListView2.Width - 300)
.Text = "Test1"
End With
For z = 1 To 200
Set Addit = ListView1.ListItems.Add(, , "Line" & Str(z))
Set Addit = ListView2.ListItems.Add(, , "Line" & Str(z))
Next z
End Sub

Private Sub VScroll1_Scroll()
ListView2.SelectedItem = ListView2.ListItems(VScroll1.Value)
ListView1.SelectedItem = ListView1.ListItems(VScroll1.Value)
End Sub

alter it to suit yourself, its free. vb 6
May 14 '10 #1
Share this Article
Share on Google+