Solved

Intercept mouse_down event over DataGridView?

Posted on 2006-10-24
4
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 86

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

710 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