|
-
Feb 12th, 2001, 08:23 AM
#1
Thread Starter
Addicted Member
Hi everyone,
I didn't think I would have such a hard time figuring this out, maybe someone can help me out...
I have a listbox which displays data. I do not want to use the horizontal scrollbar, I need my users to see all on one screen so I have two lines for the same data and all fits well. The problem is that first off I want to have both the first items from the listbox selected when the form activates. Then I need to always have two lines selected as the user uses the arrows or the mouse to select another item (in other words, I always want the pair of lines that refer to the the same data to be selected)
So it should start off with items 0 and 1 selected and if a user clicks on item 4 then items 3 and 4 should be selected. Also if they use the arrow keys to navigate through, it sould skip one item for evey key press.
Any suggestions, even some ideas just to get me started would be great
Phailak
-
Feb 12th, 2001, 09:38 AM
#2
Lively Member
This code has 2 parts part one is in the key_down section of the list box
Code:
Private Sub List1_KeyUp(KeyCode As Integer, Shift As Integer)
If List1.ListIndex / 2 = Int(List1.ListIndex / 2) Then
List1.Selected(List1.ListIndex + 1) = False
List1.Selected(List1.ListIndex) = False
If KeyCode = vbKeyUp And List1.ListIndex > 1 Then List1.Selected(List1.ListIndex - 2) = True
Else
List1.Selected(List1.ListIndex - 1) = False
List1.Selected(List1.ListIndex) = False
If KeyCode = vbKeyDown And List1.ListIndex < List1.ListCount - 1 Then List1.Selected(List1.ListIndex + 2) = True
End If
Call List1_MouseDown(0, 0, 0, 0)
End Sub
The second is in list1_mouseDown of the list box
NOTE: you must use mouse down, and not click because click triggers whenever the list1.listindex property changes.
Code:
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not List1.Selected(List1.ListIndex) Then List1.Selected(List1.ListIndex) = True
For a = 0 To List1.ListCount - 1
If List1.Selected(a) Then
If a / 2 = Int(a / 2) Then
List1.Selected(a + 1) = True
Else
List1.Selected(a - 1) = True
End If
End If
Next a
End Sub
Hope this helps,
Bios
Age: 17
Languages: (Q)BASIC, Visual Basic, Dark Basic,C/C++, Visual C++, Perl, Java Script, HTML, ASP
"DO:BEEP:LOOP"
-
Feb 12th, 2001, 10:32 AM
#3
Thread Starter
Addicted Member
Bios, thanx a lot the code works great...
i owe you one
Phailak
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|