I'm trying to select items from the listbox when pressing Enter on the selected item. Here is what I have tried so far:

Private Sub ListBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown
        Select Case e.KeyCode
            Case Keys.Enter
                ListBox1.SelectedItem = ListBox1.PerformMouseClick()
        End Select
    End Sub

Hi,
You want to select an item when the user selects the item and presses enter? But the user has just selected the item?
Looking at your code, it would appear you want the item to perform an action when the user hits enter and you may want other events to perform this action?
If this is the case, create a sub routine to perform the action(s) and in each of the sub routines that handle the events call it i.e.

Private Sub ListBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown
        Select Case e.KeyCode
            Case Keys.Enter
                ListBox1_PerformMyAction()
        End Select
End Sub


 Private sub  ListBox1_PerformMyAction()
     if ListBox1.SelectedItems.Count = 0 then
         Messagebox.Show("No Item Selected")
     Else
        '.... do whatever
     end if
 End sub
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.