Results 1 to 8 of 8

Thread: [2008] Listboxes, scrollbars question (same value).

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    155

    [2008] Listboxes, scrollbars question (same value).

    Hi guys! I'm trying to find out how to do this:
    I got 2 listboxes , when you scroll with the scrollbar
    then the other scroll bar of the listbox2 will be at the same value
    of listbox1 scrollbar value when it's being moved.

    I will try to make it simple:
    Listbox1
    Listbox2

    User moves listbox1 scrollbar, then listbox2 scrollbar will be moved to
    the same place.

    I can't find a solution for it, so I went to here.

    please try to help me.
    Thanks!

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2008] Listboxes, scrollbars question (same value).

    vb Code:
    1. listbox2.TopIndex = listbox1.TopIndex

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2008] Listboxes, scrollbars question (same value).

    Quote Originally Posted by .paul.
    vb Code:
    1. listbox2.TopIndex = listbox1.TopIndex
    So long as both listboxes contain the same number of items always.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    155

    Re: [2008] Listboxes, scrollbars question (same value).

    thanks, but I want this to happen when the user scrolls
    but I can't find something like:
    Private Sub ListBox1_ScrollValue change(ByVal Sender...)

    I mean where do I put the code so when the scroll is moved , the other will move too?

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2008] Listboxes, scrollbars question (same value).

    heres an extended listbox control with a scrolled event

    vb Code:
    1. Public Class listboxEx
    2.     Inherits ListBox
    3.  
    4.     Private WM_VSCROLL As Integer = &H115
    5.  
    6.     Public Event scrolled()
    7.  
    8.     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    9.  
    10.         If m.Msg = WM_VSCROLL Then
    11.             RaiseEvent scrolled()
    12.         End If
    13.  
    14.         MyBase.WndProc(m)
    15.     End Sub
    16.  
    17. End Class

    heres how to handle it in your form

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         Dim items() As String = {"item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9", "item10"}
    5.         ListboxEx1.Items.AddRange(items)
    6.         ListBox2.Items.AddRange(items)
    7.     End Sub
    8.  
    9.     Private Sub ListboxEx1_scrolled() Handles ListboxEx1.scrolled
    10.         ListBox2.TopIndex = ListboxEx1.TopIndex
    11.     End Sub
    12.  
    13. End Class

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    155

    Re: [2008] Listboxes, scrollbars question (same value).

    Hi again, well, it sounds complicated more then I excpected.
    are you sure there is no easier way?

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2008] Listboxes, scrollbars question (same value).

    sorry for the delay.
    its quite simple really.
    add a new class to your project, call it listboxEx.
    then paste the code from the first box above into the class.
    run your project, stop it, then at the top of your toolbox you find listboxEx - the extended listbox control - which has a scrolled event you can use

    vb Code:
    1. Private Sub ListboxEx1_scrolled() Handles ListboxEx1.scrolled
    2.     ListBox2.TopIndex = ListboxEx1.TopIndex
    3. End Sub

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    155

    Re: [2008] Listboxes, scrollbars question (same value).

    Thanks ! I will try it when I will be home! Thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width