Ticket Q424792
Visible to All Users

Detect the column header region in the mouse down event of a grid

created 13 years ago

I need to detect if the mouse is over the column headers and suppress my custom pop-up menu. The built in popup menus displays together with mine. I want to suppress my pop-up and show the grid header popup menu only. How would I do that?

I'm using this code:

Private Sub GridControl1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles GridControl1.MouseDown
'MsgBox(e.Location.ToString)
'have to take into account nav3 dimensions hosting form
'lets suppress this for awhile
Dim x As Integer = e.X + Nav3.NavBarControl1.Width
Dim y As Integer = e.Y + Nav3.RibbonControl.Height
Dim p As New System.Drawing.Point(x, y)

If e.Button = Windows.Forms.MouseButtons.Right Then
Me.PopupMenu1.ShowPopup§
End If
End Sub

Comments (1)

    image when not in the header section with right click

    Answers approved by DevExpress Support

    created 13 years ago (modified 13 years ago)

    Construct a GridHitInfo object; this will tell you if the user is pressing the mouse down on a column header, group panel etc…

    C#
    private void gridView1_MouseDown(object sender, MouseEventArgs e) { GridHitInfo hitInfo = gridView1.CalcHitInfo(e.Location); if (hitInfo.InColumnPanel) { //do something } }

    See also:

    * Hit Information Overview

    * Samples of Using Hit Information

      Comments (1)

        Hi Brendon,
        Thank you for a quick and accurate response, I have included my code for vb.net users who may be using a banded grid.
        Private Sub GridControl1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) _
         Handles GridControl1.MouseDown
                If e.Button = Windows.Forms.MouseButtons.Right Then

        Dim hitinfo As DevExpress.XtraGrid.Views.BandedGrid.ViewInfo.BandedGridHitInfo = AdvBandedGridView1.CalcHitInfo(e.Location)
                    If hitinfo.InRow Or hitinfo.InRowCell Then

        'have to take into account nav3 dimensions
                        Dim x As Integer = e.X + Nav3.NavBarControl1.Width + 5 'splitter bar
                        Dim y As Integer = e.Y + Nav3.RibbonControl.Height + 33 'lbl at top
                        Dim p As New System.Drawing.Point(x, y)
                        Me.PopupMenu1.ShowPopup§
                    Else
                        'use builtin popups
                    End If
                End If
            End Sub

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.