Synchronised Listviews

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lonnie50
    New Member
    • May 2010
    • 1

    Synchronised Listviews

    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

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

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

    Private Sub VScroll1_Scroll ()
    ListView2.Selec tedItem = ListView2.ListI tems(VScroll1.V alue)
    ListView2.Selec tedItem.EnsureV isible
    ListView1.Selec tedItem = ListView1.ListI tems(VScroll1.V alue)
    ListView1.Selec tedItem.EnsureV isible
    End Sub


    alter it to suit yourself, its free. vb 6
Working...