Solved

Intercept mouse_down event over DataGridView?

Posted on 2006-10-24
4
357 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

807 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