Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scrolling a list box up and down with two buttons

Status
Not open for further replies.
Joined
Jun 30, 2003
Messages
196
Location
GB
hi

i have two directional buttons, up and down, i also have a list box with about six items. I want it so when the user presses up or down on the directional buttons the selection within the list box moves appropriately, does any one know how i can acheive such functionality.

Thanks
Dan

 
Code:
sub btnMoveDownList_Click()
  if list1.listindex < list1.listcount -1 then
    list1.listindex = list1.listindex +1
  end if

end sub
 
So jeff new thread new topic. Hope you read my post on 'why im jumping through al these hoops'

The above code will allow me to scroll down the list i take it, but i have an extension to the above problem.

what if not all the list options can be fitted on one page:

On one of my forms i want the user to be presented with a list of options (like that on a mobile phone) but of course not all the options can be displayed at once. I want the system to allow the user to press up and down to scroll through each option, changing its apperance depending if currently selected or not. But as i said not all the options can fit on screen, so when the user clicks down whilst the last option is highlighted the options below should beocome visible and all the options move up, therfore the top option should dissapear of screen.

I hope this makes sense.

I was hoping i could use a list box but not sure this would allow me to use the directional keys to navigate through the options and change there appearance, also not sure if i could create the functionality described above whereby when down is pressed on the last displayed option another one beocomes visible and the top one dissaperas. What do you think, any ideas

Thanks again Dan
 
>> But as i said not all the options can fit on screen, so when the user clicks down whilst the last option is highlighted the options below should beocome visible and all the options move up, therfore the top option should dissapear of screen.
<<

Basic functionality of a listbox.
 
ok jeff tryed your code it works a treat two little things however.

could you explain what the code does so i can try to convert it to work for the up button as well. and how do i set it so the top item in the list is highlighted when i start the form and when the user presses down once it moves to the next item.

thanks
 
.listindex tells you where the selection currently is.
In the down code, I check to see if it is at the end.
If not, I add 1

For the up code, check to see if it is 0
If not, subtract 1

When the form opens, set the listindex to 0
 
Hi jeff

I used this code to move up the list, and it works but not sure if it is the correct solution what do you think?

Private Sub cmdKeypadUp_Click()

If lstMessages.ListIndex < lstMessages.ListCount + 1 Then
lstMessages.ListIndex = lstMessages.ListIndex - 1
End If

End Sub

Cheers
 
I don't want to keep writing your program.
Ask yourself, under what circumstances would it be daft to deduct 1 from the current value?
(Hint: read my previous post)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top