2011-09-19 78 views
0

我試圖在我的datagridview上顯示一個自定義的contextmenustrip,除了當單元格正在被編輯時它工作正常。然後它顯示默認窗口contextmenustrip與複製/剪切/ ...vb.net DataGridview在正在編輯的單元格上顯示自定義的ContextMenuStrip

有沒有辦法來覆蓋DataGridViewTextBoxCell contextmenustrip或禁用它?

Disable DataGridView System ContextMenu的解決方案does not工作給我。

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 

回答

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 
相關問題