none
Mouse Wheel Click RRS feed

  • Question

  • Hi all

    I'm using a Datagridview in a Form bound to dataTable and DGTV.selectionMode= Fullrowselect

    It seems to me that a click on the mouse wheel does not the same job as mouse left click. 

    In particular the Binding Source Position does not change clicking on Mouse wheel

    So I have two choises

    1) disable click on Mouse wheel or

    2) have the DGV.MouseClick (middle) do the same task as DGV.CellMouseClick 

    How to do both of them ?


    • Edited by Claudio111 Monday, August 27, 2018 8:39 AM
    Monday, August 27, 2018 7:36 AM

Answers

  • Hi,

    Disable mouse wheel:

    Imports System.Data.SqlClient
    Public Class Form1
        Inherits Form
        Implements IMessageFilter
    
        Dim constr As String = "Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;AttachDbFileName= C:\Users\alexl2\Desktop\DataBase\Alex\alex.mdf"
        Dim conn As SqlConnection
        Dim sda As SqlDataAdapter
        Dim dt As DataTable
        Dim bind As New BindingSource
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Application.AddMessageFilter(Me)
            DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
            Using conn = New SqlConnection(constr)
                conn.Open()
                sda = New SqlDataAdapter("Select * From Student", conn)
                dt = New DataTable()
                sda.Fill(dt)
                DataGridView1.DataSource = dt
            End Using
    
        End Sub
    
        Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
            If m.Msg = 522 Then
                Return True
            Else
                Return False
            End If
        End Function
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Claudio111 Monday, August 27, 2018 10:30 AM
    Monday, August 27, 2018 9:14 AM

All replies

  • Hi,

    Disable mouse wheel:

    Imports System.Data.SqlClient
    Public Class Form1
        Inherits Form
        Implements IMessageFilter
    
        Dim constr As String = "Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;AttachDbFileName= C:\Users\alexl2\Desktop\DataBase\Alex\alex.mdf"
        Dim conn As SqlConnection
        Dim sda As SqlDataAdapter
        Dim dt As DataTable
        Dim bind As New BindingSource
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Application.AddMessageFilter(Me)
            DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
            Using conn = New SqlConnection(constr)
                conn.Open()
                sda = New SqlDataAdapter("Select * From Student", conn)
                dt = New DataTable()
                sda.Fill(dt)
                DataGridView1.DataSource = dt
            End Using
    
        End Sub
    
        Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
            If m.Msg = 522 Then
                Return True
            Else
                Return False
            End If
        End Function
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Claudio111 Monday, August 27, 2018 10:30 AM
    Monday, August 27, 2018 9:14 AM
  • Hi

    Do 'ENTER' for middle mouse click.

    (Indiscriminate method though)

      Private Sub DGV_MouseClick(sender As Object, e As MouseEventArgs) Handles DGV.MouseClick
        If e.Button = MouseButtons.Middle Then
          SendKeys.Send("{Enter}")
        End If
      End Sub


    Regards Les, Livingston, Scotland

    Monday, August 27, 2018 1:04 PM