Home All Groups Group Topic Archive Search About

Datagrid Context Menu

Author
14 Dec 2006 11:33 AM
owenmj
If I have a datagrid with an attached context menu, how can prevent the
context menu from opening if it is not over a row in the grid?

Regards,
owenmj

Author
14 Dec 2006 12:05 PM
vbnetdev
assuming you are still on VS 2003.

Private Sub MyDataGrid_MouseDown(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.MouseEventArgs) _
    Handles MyDataGrid.MouseDown
  Dim hi As System.Windows.Forms.DataGrid.HitTestInfo
  hi = MyDataGrid.HitTest(e.X, e.Y)

  ' Test if the clicked area was a cell.
  If hi.Type = DataGrid.HitTestType.Cell Then
     Me.MyDataGrid.ContextMenu = Me.GridContextMenu
     Me.manipulatedRow = hi.Row
     Me.manipulatedColumn = hi.Column
      Else
    Me.MyDataGrid.ContextMenu = Nothing
  End If
End Sub
Show quoteHide quote
"owenmj" <owe***@discussions.microsoft.com> wrote in message
news:B54E58E7-B15E-429A-81F4-28E0C19BE467@microsoft.com...
> If I have a datagrid with an attached context menu, how can prevent the
> context menu from opening if it is not over a row in the grid?
>
> Regards,
> owenmj