Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Intercept mouse_down event over DataGridView?

Posted on 2006-10-24
4
Medium Priority
?
363 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 2000 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

688 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