Hi,
I read many articles about this, but I still couldn't manage to solve it. I want to select the item of a listbox with MouseEnter event.

It should be something similar like this

Private Sub LBox_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles LBox.MouseDown
        If e.Button = MouseButtons.Right Then
            Dim index As Integer = LBox.IndexFromPoint(New Point(e.X, e.Y))
            If index >= 0 Then
                LBox.SelectedItem = LBox.Items(index)
                Debug.Print(LBox.SelectedItem)
            End If
        End If
    End Sub

Would appreciate your help.
Thank you.

You can do it by

Private Sub ListBox1_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseMove

    Dim G As System.Drawing.Graphics = Graphics.FromHwnd(Me.Handle)
    Dim item As String

    item = ListBox1.IndexFromPoint(New Point(e.X, e.Y))

    If item >= 0 Then
        TextBox1.Text = ListBox1.Items(item)
    End If

End Sub

It shows error message:

'X' is not a member of 'System.EventArgs'.  
'Y' is not a member of 'System.EventArgs'.

Hi,

Thanks. I changed MouseEnter Event to MouseMove Event for all controls. Now, I am getting problem with ComboBox.

Could you please help me to do the same thing with comboBox?

Would appreciate your help

The MouseMove appears to operate only within the text area of the combobox and not when the dropdown is active. I don't have anything to suggest in this case but because the original question has been resolved please mark this thread as solved.

Edited 3 Years Ago by Reverend Jim

This question has already been answered. Start a new discussion instead.