Solved

Intercept mouse_down event over DataGridView?

Posted on 2006-10-24
4
346 Views
Last Modified: 2007-12-19
I've drawn a square (in the DGV_Paint sub) on top of a DataGridView control and when I click on it I don't want the underlying DataGridView to see the click event. Ideally there would be an e.handled property for mouse_down but there isn't. What I get is a cell_changed event in the DataGridView control which is causing me problems. There are some rather ugly ways around this but I am looking for something prettier.
0
Comment
Question by:tmostad
4 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17799727
Try either Inheriting from DataGridView or using the NativeWindow() class:

Public Class TestForm

    Private mdgv As MyDataGridView

    Private Sub TestForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        mdgv = New MyDataGridView(Me.DataGridView1)
    End Sub

    Private Class MyDataGridView
        Inherits NativeWindow

        Private dgv As DataGridView
        Private Const WM_LBUTTONDOWN As Integer = &H201

        Public Sub New(ByVal dgv As DataGridView)
            If Not (dgv Is Nothing) Then
                Me.dgv = dgv
                Me.AssignHandle(dgv.Handle)
            End If
        End Sub

        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            Select Case m.Msg
                Case WM_LBUTTONDOWN
                    Debug.Print("WM_LBUTTONDOWN")
                    ' do something in here and call "exit sub" to suppress the msg if necessary...
                    Exit Sub

            End Select

            MyBase.WndProc(m)
        End Sub

    End Class

End Class
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17799752
there is no cellchanged event in datagridview, what do you mean?

in case this helps,
Mouse events occur in the following order:

MouseEnter

MouseMove

MouseHover / MouseDown / MouseWheel

MouseUp

MouseLeave

0
 
LVL 1

Author Comment

by:tmostad
ID: 17799819
Sorry, I meant CurrentCellChanged event. I used that event to do stuff when the user actually wants to change cells not when the square above the DGV is clicked.
0
 
LVL 1

Expert Comment

by:almondmitchell
ID: 17826065
Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
        If DataGrid1.MouseButtons = MouseButtons.Left Then
            MsgBox("left mouse button pressed")
        End If
End sub
       
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now