vb.net DataGridview在正在编辑的单元格上显示自定义ContextMenuStrip

时间:2011-09-19 12:14:21

标签: vb.net contextmenustrip datagridviewtextboxcell

我正在尝试在我的datagridview上显示自定义contextmenustrip,除了正在编辑单元格外,它工作正常。然后它显示默认的窗口contextmenustrip with copy / cut / ...

有没有办法覆盖DataGridViewTextBoxCell contextmenustrip或禁用它?

来自Disable DataGridView System ContextMenu的解决方案对我无效。

Private Sub DataGridView1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DocCostGroupDetsDataGridView.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Right Then
            _CustomContextMenuStrip.fGetContextMenu()
            _CustomContextMenuStrip.Show(DataGridView1, e.Location)
        End If
    End Sub

1 个答案:

答案 0 :(得分:0)

Private Sub DataGridView1_EditingControlShowing(ByVal sender As System.Object, _
                    ByVal e As DataGridViewEditingControlShowingEventArgs) _
                    Handles DataGridView1.EditingControlShowing
       If TypeOf e.Control Is TextBox Then
          With DirectCast(e.Control, TextBox)
             .ContextMenuStrip = ContextMenuStrip2
          End With
       End If
End Sub