DebsP via OfficeKB.com
2006-08-10 11:57:25 UTC
Hi All
Apologies for re-submitting this. Am worried it won't get answered as had a
response that was an observation rather than an answer. Rather keen to get
the latter & not sure if anyone else would pick it up.
I am trying to write what I'ms sure should be some simple little bit of code
to continuously loop through items in a dropdown list when the user presses
the up/down cursor keys. If the user is on the last item in a list then I
want the down cursor key to move to the first item; if on the first item then
the up cursor key should move to the last item in the list. In between it
should just move up/down as you would expect it to.
This is the code I have:
***********************************
Public Sub Scroll_Dropdown(cmbName As ComboBox, KeyCode)
'40 - cursor down
'38 - cursor up
'down cursor & list item is either blank or on the last item - select the
first item in the list
If (KeyCode = 40 And cmbName.ListIndex = -1) Or (KeyCode = 40 And cmbName.
ListIndex = cmbName.ListCount - 1) Then
cmbName.ListIndex = 0
'otherwise, if down cursor, add 1 to the current list index to select the
next item in the list
ElseIf KeyCode = 40 Then
cmbName.ListIndex = cmbName.ListIndex + 1
'up cursor and list item is either blank or on the first item in the list -
select the last item in the list
ElseIf (KeyCode = 38 And cmbName.ListIndex = -1) Or (KeyCode = 38 And cmbName.
ListIndex = 0) Then
cmbName.ListIndex = cmbName.ListCount - 1
'otherwise, if up cursor, subtract 1 from the current list index to select
the previous item
ElseIf KeyCode = 38 Then
cmbName.ListIndex = cmbName.ListIndex - 1
End If
End Sub
***********************************
The problem is that it sometimes jumps two items at a time. I'm sure there's
a simple explanation but I just can't see it.
Thanks in advance for any help.
ArchieD
Apologies for re-submitting this. Am worried it won't get answered as had a
response that was an observation rather than an answer. Rather keen to get
the latter & not sure if anyone else would pick it up.
I am trying to write what I'ms sure should be some simple little bit of code
to continuously loop through items in a dropdown list when the user presses
the up/down cursor keys. If the user is on the last item in a list then I
want the down cursor key to move to the first item; if on the first item then
the up cursor key should move to the last item in the list. In between it
should just move up/down as you would expect it to.
This is the code I have:
***********************************
Public Sub Scroll_Dropdown(cmbName As ComboBox, KeyCode)
'40 - cursor down
'38 - cursor up
'down cursor & list item is either blank or on the last item - select the
first item in the list
If (KeyCode = 40 And cmbName.ListIndex = -1) Or (KeyCode = 40 And cmbName.
ListIndex = cmbName.ListCount - 1) Then
cmbName.ListIndex = 0
'otherwise, if down cursor, add 1 to the current list index to select the
next item in the list
ElseIf KeyCode = 40 Then
cmbName.ListIndex = cmbName.ListIndex + 1
'up cursor and list item is either blank or on the first item in the list -
select the last item in the list
ElseIf (KeyCode = 38 And cmbName.ListIndex = -1) Or (KeyCode = 38 And cmbName.
ListIndex = 0) Then
cmbName.ListIndex = cmbName.ListCount - 1
'otherwise, if up cursor, subtract 1 from the current list index to select
the previous item
ElseIf KeyCode = 38 Then
cmbName.ListIndex = cmbName.ListIndex - 1
End If
End Sub
***********************************
The problem is that it sometimes jumps two items at a time. I'm sure there's
a simple explanation but I just can't see it.
Thanks in advance for any help.
ArchieD
--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200608/1
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200608/1