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.

Are you programming in WPF or Winforms?

Winforms

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'.

Thank you. I need to do with MouseEnter event.

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.

Thanks

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.