PDA

Click to See Complete Forum and Search --> : Highlighted items from a listbox


Phailak
Feb 12th, 2001, 07:23 AM
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

Bios
Feb 12th, 2001, 08:38 AM
This code has 2 parts part one is in the key_down section of the list box

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.


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



:D Hope this helps,

Phailak
Feb 12th, 2001, 09:32 AM
Bios, thanx a lot the code works great...

i owe you one

Phailak