
10-06-2006, 05:43 PM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,722
|
|
Well,  , a bit cheesy perhaps, but you could save the listindex as you go, and check the selection and if it contains something to identify is as unselectable, set the index back to what it was before.
Of course, if they use the arrow key to scroll up or down, this code will prevent you from scrolling out of a section. You could probably add other code to get around that situation. One option, rather than set the index back to what it was, if the old index was less than the current index, you're moving down the list so set the listIndex to ListIndex + 1.
Set to ListIndex - 1 if moving up the list.
Code:
Option Explicit
Dim LastIndex As Long
Private Sub Form_Load()
Dim i As Integer, j As Integer
'Load up some test conditions
For i = 1 To 3
List1.AddItem "--Section " & CStr(i) & " --"
For j = 1 To 5
List1.AddItem "Item" & CStr(j)
Next
Next
End Sub
Private Sub List1_Click()
If Left$(List1.Text, 2) = "--" Then
List1.ListIndex = LastIndex
Else
LastIndex = List1.ListIndex
End If
End Sub
Edit: The skip up/down version.
Code:
Private Sub List1_Click()
If Left$(List1.Text, 2) = "--" Then
If LastIndex < List1.ListIndex Then
List1.ListIndex = List1.ListIndex + 1
Else
List1.ListIndex = List1.ListIndex - 1
End If
End If
LastIndex = List1.ListIndex
End Sub
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Last edited by passel; 10-06-2006 at 05:50 PM.
|