JoshDB

Ok here is a . How would i make it so if you press lets say the A button it will take the listbox and move it to a certain item. For exampel(i know this is not right):

Code Snippet
If A is pressed move Listbox1 to selection "Able"

Just an example i know it is the right code but how would i go of doing this.



Re: Visual Basic Express Edition Button Press....

DMan1

Use the Keypress event of the ListBox:

Code Snippet

Private Sub ListBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ListBox1.KeyPress

Dim Count As Integer = 0

If e.KeyChar = "A" Then

For Each s As String In ListBox1.Items

If s(0) = "A" Then

ListBox1.SelectedIndex = Count

Exit For

End If

Count += 1

Next

End If

End Sub






Re: Visual Basic Express Edition Button Press....

JoshDB

That works!



Re: Visual Basic Express Edition Button Press....

DMan1

Set the form's "KeyPreview" property to true and then use the same code in the forms keypress event