0

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.

3
Contributors
8
Replies
47
Views
3 Years
Discussion Span
Last Post by nikki05
Featured Replies
  • 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 Read More

1

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
0

It shows error message:

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

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

0

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 by Reverend Jim

This question has already been answered. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.