[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!
Re: [2008] Listboxes, scrollbars question (same value).
vb Code:
listbox2.TopIndex = listbox1.TopIndex
Re: [2008] Listboxes, scrollbars question (same value).
Quote:
Originally Posted by .paul.
vb Code:
listbox2.TopIndex = listbox1.TopIndex
So long as both listboxes contain the same number of items always.
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?
Re: [2008] Listboxes, scrollbars question (same value).
heres an extended listbox control with a scrolled event
vb Code:
Public Class listboxEx
Inherits ListBox
Private WM_VSCROLL As Integer = &H115
Public Event scrolled()
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_VSCROLL Then
RaiseEvent scrolled()
End If
MyBase.WndProc(m)
End Sub
End Class
heres how to handle it in your form
vb Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim items() As String = {"item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9", "item10"}
ListboxEx1.Items.AddRange(items)
ListBox2.Items.AddRange(items)
End Sub
Private Sub ListboxEx1_scrolled() Handles ListboxEx1.scrolled
ListBox2.TopIndex = ListboxEx1.TopIndex
End Sub
End Class
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?
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:
Private Sub ListboxEx1_scrolled() Handles ListboxEx1.scrolled
ListBox2.TopIndex = ListboxEx1.TopIndex
End Sub
Re: [2008] Listboxes, scrollbars question (same value).
Thanks ! I will try it when I will be home! Thanks again!