Listbox and scrolling with arrow keys

G

gv

Hi all,

Using VB 2005 Express

When pressing the down key in a listbox and getting to the last item I want
to
move right back to the top and vise versa so it never stops when pressing
the
arrow keys. The code below moves it when it gets to the end of the list biut
skips the first item
and moves to index 1.

Private Sub ListBox1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown

If ListBox1.SelectedIndex = (ListBox1.Items.Count - 1) And e.KeyCode =
Keys.Down Then

ListBox1.SetSelected(0, True)

End If

End Sub

thanks
Gerry
 
L

Larry Lard

gv said:
Hi all,

Using VB 2005 Express

When pressing the down key in a listbox and getting to the last item I want
to
move right back to the top and vise versa so it never stops when pressing
the
arrow keys. The code below moves it when it gets to the end of the list biut
skips the first item
and moves to index 1.

Private Sub ListBox1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown

If ListBox1.SelectedIndex = (ListBox1.Items.Count - 1) And e.KeyCode =
Keys.Down Then

ListBox1.SetSelected(0, True)

Here add

e.Handled = True
End If

End Sub

This will prevent the normal keydown operation happening, which is what
is moving the selection from 0 to 1 after you have set it.
 
G

gv

Thank You!!!!!
Gerry

Larry Lard said:
Here add

e.Handled = True


This will prevent the normal keydown operation happening, which is what
is moving the selection from 0 to 1 after you have set it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top