I have 2 listbox's. Checkbox is enabled on both.
Listbox1
Listbox2
Both listboxes contain the same exact items. When I scroll in listbox1, I
would like listbox2 to scroll in sync with listbox1.
Does anyone have any code examples?
Thanks,
David
Use the listbox Scroll event to sync the TopIndex properties. Ideally
you should use a flag variable to prevent setting the TopIndex prop in
one from firing the Scroll event in the other. (Saves a few CPU
cycles.)
Dim m_NoScroll As Boolean 'module-level flag var
Private Sub List1_Scroll()
If Not m_NoScroll Then
m_NoScroll = True
List2.TopIndex = List1.TopIndex
m_NoScroll = False
End If
End Sub
Private Sub List2_Scroll()
If Not m_NoScroll Then
m_NoScroll = True
List1.TopIndex = List2.TopIndex
m_NoScroll = False
End If
End Sub
==============
Alternatively if you used an ~array~ of listboxes, you could use a
local Static var for the flag:
Private Sub List1_Scroll(Index As Integer)
Static NoScroll As Boolean
If Not NoScroll Then
NoScroll = True
If Index = 0 Then
List1(1).TopIndex = List1(0).TopIndex
Else
List1(0).TopIndex = List1(1).TopIndex
End If
NoScroll = False
End If
End Sub
-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
I'm converting some code from VB3 to VB6 and there's an API call being
performed that's supposed to identify if an item is in a listbox...
'Declare Function SendMessageByString& _
' Lib "User" Alias "SendMessage" ( _
' ByVal hwnd%, ByVal wMsg%, _
' ByVal wParam%, ByVal lParam$)
Declare Function SendMessageByString Lib "user32.dll" _
Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Pos& = SendMessageByString(lstPlts.hwnd, _
LB_FINDSTRINGEXACT, -1, strPlant)
The SendMessageByString is an API call to SendMessageA (was originally a
16-bit SendMessage).
Is there a better method to finding information in the listbox? The
transformation from 16-bit SendMessage to 32-bit SendMessageA broke the API
call... and the old parameter of LB_FINDSTRINGEXACT was/is set to:
Global Const WM_USER = &H400
Global Const CB_FINDSTRING = (WM_USER + 12)
Global Const CB_FINDSTRINGEXACT = (WM_USER + 24)
That might be wrong, I'm looking for references to the SendMessageA to see
if I can modify it to make it work and if worst comes to worst I'll just
For/Next it.
--
Jim Carlock
http://www.microcosmotalk.com
Feel free to post back to the newsgroup for all to witness!
Const WM_USER = &H400
Const LB_FINDSTRINGEXACT = (WM_USER + 35)
That comes out to &H423.
I found something at http://www.mvps.org/vbnet
Going to try the following:
Private Const LB_FINDSTRING = &H18F
Private Const LB_FINDSTRINGEXACT = &H1A2
--
Jim Carlock
http://www.microcosmotalk.com
Feel free to post back to the newsgroup for all to witness!
"Jim Carlock" <nos...@127.0.0.1> wrote in message
news:%2352Tj52...@tk2msftngp13.phx.gbl...
If anyone has another suggestion as to how to fill a listbox with unique
values...
What's happening, is 600+ records are being read and two listboxes are being
filled. Only unique values are being placed into the listboxes. I'm thinking
about breaking it up into two different queries... a query to find unique
values in a database will work fine as well... It all happens so fast that
there's no noticeable difference. However if it's done on a 386... oh well,
no use thinking about that.
Open to any other suggestions... I have two methods in mind, the one I just
fixed is working fine until the API changes again.
Dim Pos as Long, hw as Long
Const LB_FINDSTRINGEXACT = &H1A2
hw = List1.hwnd
Pos& = SendMessageByString(hw, _
LB_FINDSTRINGEXACT, -1, ByVal (strStuff))
If Pos& = -1 Then
' string wasn't found, add to list
List1.AddItem strStuff
End If
You'll need to make sure you don't send a Null string "" into the API call.
Thanks to Randy Birch'es website, http://www.mvps.org/vbnet for the
clarification on the proper constant to use!
If you're using VB6, look into the Scroll Event:
Sub List1_Scroll( ...
List1.TopIndex = List1.TopIndex
End Sub
HTH,
Phill W.