Merging a custom ContextMenuStrip with the system edit context menu in a DataGridView

Posted by Tom on Stack Overflow See other posts from Stack Overflow or by Tom
Published on 2008-10-29T15:04:45Z Indexed on 2010/03/14 16:45 UTC
Read the original article Hit count: 280

Filed under:
|
|

I have a DataGridView in a VB.NET app that I have limited to cell selection only. The control has two columns, the first is not editable, the second is editable. I have a ContextMenuStrip that provides some additional functionality and I am able to make it appear when an editable cell receives a right click and is not in edit mode. Based on an example in a Microsoft forum, I am able to now show the context menu when an editable cell receives a right click while also in edit mode. That code is as follows:

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

This, however, completely overwrites the system context menu of the editing control. How can I merge my Context Menu Strip (ContextMenuStrip1) with the system context menu?

For further information, I am using VS2008, but targeting the .NET 2.0 platform.

© Stack Overflow or respective owner

Related posts about datagridview

Related posts about .NET