Hi,

I have the following code which works pretty fine with Listview. But I would like to use it with computer keyboard up/down arrow keys. How to modify the following code? Please do help.

Private Sub LVW_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LVW.Click

        txtTAID.Text = LVW.SelectedItems(0).Text
        txtVNO.Text = LVW.SelectedItems(0).SubItems(1).Text
        txtVNM.Text = LVW.SelectedItems(0).SubItems(2).Text
    End Sub

you need to handle the keydown event of the control.

you need to handle the keydown event of the control.

Private Sub LVW_KEYDOWN()
        txtTAID.Text = LVW.SelectedItems(0).Text
        txtVNO.Text = LVW.SelectedItems(0).SubItems(1).Text
        txtVNM.Text = LVW.SelectedItems(0).SubItems(2).Text
   End Sub

It also doesn't work. Any help with example, please.

Regards.

You should go to the events of the listview and handle Keypress event. Then in the event, you should use the case method like this:

Select Case e.KeyChar
case 37: // <--- left arrow.
        // do stuff for Left Arrow here.
    case 38: // <--- up arrow.
// do stuff for Up Arrow here.
case 39: // <--- right arrow.
// do stuff for Right Arrow here.
case 40: // <--- down arrow.
// do stuff for Down Arrow here.
End Select

Hope i helped!

You should go to the events of the listview and handle Keypress event. Then in the event, you should use the case method like this:

Select Case e.KeyChar
case 37: // <--- left arrow.
        // do stuff for Left Arrow here.
    case 38: // <--- up arrow.
// do stuff for Up Arrow here.
case 39: // <--- right arrow.
// do stuff for Right Arrow here.
case 40: // <--- down arrow.
// do stuff for Down Arrow here.
End Select

Hope i helped!

I am getting an error: Name 'e' is not declared. How can I declare it? Please help.

Private Sub LVW_KEYPRESS()
        Select Case e.KeyChar
            Case 37 '<--- left arrow.
                txtTAID.Text = LVW.SelectedItems(0).Text
                txtVNO.Text = LVW.SelectedItems(0).SubItems(1).Text
                txtVNM.Text = LVW.SelectedItems(0).SubItems(2).Text
            Case 38 '<--- up arrow.
                txtTAID.Text = LVW.SelectedItems(0).Text
                txtVNO.Text = LVW.SelectedItems(0).SubItems(1).Text
                txtVNM.Text = LVW.SelectedItems(0).SubItems(2).Text
            Case 39 '<--- right arrow.
                txtTAID.Text = LVW.SelectedItems(0).Text
                txtVNO.Text = LVW.SelectedItems(0).SubItems(1).Text
                txtVNM.Text = LVW.SelectedItems(0).SubItems(2).Text
            Case 40 '<--- down arrow.
                txtTAID.Text = LVW.SelectedItems(0).Text
                txtVNO.Text = LVW.SelectedItems(0).SubItems(1).Text
                txtVNM.Text = LVW.SelectedItems(0).SubItems(2).Text
        End Select
    End Sub

The method you are using is completely wrong mate... :S


When on visual studio do the following:
1)Click the listview
2)Then go on the properties panel
3)on top, there is a lighting bolt...Click it
4)Search for 'Keypress' Event
5)Double click the textbox in the right
6)Post the code that i provided.

Cheers :D

The method you are using is completely wrong mate... :S


When on visual studio do the following:
1)Click the listview
2)Then go on the properties panel
3)on top, there is a lighting bolt...Click it
4)Search for 'Keypress' Event
5)Double click the textbox in the right
6)Post the code that i provided.

Cheers :D

Thanks a lot for your kind help. I am sorry, actually I was looking for the keyup & keydown event but it was my mistake to mention as keypress event.

The following code works fine for keyup & key down events:

Private Sub LVW_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles LVW.KeyDown
        txtTAID.Text = LVW.SelectedItems(0).Text
        txtVNO.Text = LVW.SelectedItems(0).SubItems(1).Text
        txtVNM.Text = LVW.SelectedItems(0).SubItems(2).Text
    End Sub
Private Sub LVW_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles LVW.KeyUp
        txtTAID.Text = LVW.SelectedItems(0).Text
        txtVNO.Text = LVW.SelectedItems(0).SubItems(1).Text
        txtVNM.Text = LVW.SelectedItems(0).SubItems(2).Text
    End Sub

I am eagerly waiting for search button code for which there is a post. Please help me out.

Once again thanks for your kind reply.

No problem mate :)

I am eagerly waiting for search button code for which there is a post. Please help me out.

Could you be more spesific? What post?

No problem mate :)

Could you be more spesific? What post?

Thanks for the reply. It is solved.

Regards.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.