Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Datagridview, contextmenu of rowtemplate doesn't show submenu's
 

Datagridview, contextmenu of rowtemplate doesn't show submenu's

I've created a datagridview which shows several customers. My contextmenu ( with submenu's ) is added to the rowtemplate as it's contextmenustrip. When i rightclick a row it does show the contextmenu, but not the submenu's. If i add the same contextmenu to the datagridview as it's contextmenu, it wil show the submenu's.

What am I missing here?
  • Moved byeryangMSFTFriday, August 21, 2009 6:31 AM (From:.NET Base Class Library)
  • Moved byTaylorMichaelLMVPWednesday, August 19, 2009 1:50 PMUnable to move thread
  •  
peer1979  Wednesday, August 19, 2009 11:57 AM

Could you please show us your code? You can also upload a demo for us to test. Skydrive (http://skydrive.live.com/ ) may be a good option. You can sign up 25GB free space only with your Windows Live Passport.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Wednesday, August 26, 2009 7:25 AM
I've created a sample project which shows the same problem. If you select a row and rightclick it to select the contextmenu, the submenu won't appear. If you do the same with the button, it will appear. It is the same contextmenu.

Can anyone point me in the right direction?

form1.designer.vb

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.DataGridView1 = New System.Windows.Forms.DataGridView
        Me.ContextMenuStrip1 = New System.Windows.Forms.ContextMenuStrip(Me.components)
        Me.Menuitem1ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.MenuItem2ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.MenuItem3ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.SubMenuAToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.SubMenuBToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.SubMenuCToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.Button1 = New System.Windows.Forms.Button
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.ContextMenuStrip1.SuspendLayout()
        Me.SuspendLayout()
        '
        'DataGridView1
        '
        Me.DataGridView1.AllowUserToAddRows = False
        Me.DataGridView1.AllowUserToDeleteRows = False
        Me.DataGridView1.AllowUserToOrderColumns = True
        Me.DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
        Me.DataGridView1.Location = New System.Drawing.Point(12, 12)
        Me.DataGridView1.Name = "DataGridView1"
        Me.DataGridView1.RowTemplate.ContextMenuStrip = Me.ContextMenuStrip1
        Me.DataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect
        Me.DataGridView1.ShowEditingIcon = False
        Me.DataGridView1.Size = New System.Drawing.Size(440, 172)
        Me.DataGridView1.TabIndex = 0
        '
        'ContextMenuStrip1
        '
        Me.ContextMenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.Menuitem1ToolStripMenuItem, Me.MenuItem2ToolStripMenuItem, Me.MenuItem3ToolStripMenuItem})
        Me.ContextMenuStrip1.Name = "ContextMenuStrip1"
        Me.ContextMenuStrip1.Size = New System.Drawing.Size(144, 70)
        '
        'Menuitem1ToolStripMenuItem
        '
        Me.Menuitem1ToolStripMenuItem.Name = "Menuitem1ToolStripMenuItem"
        Me.Menuitem1ToolStripMenuItem.Size = New System.Drawing.Size(143, 22)
        Me.Menuitem1ToolStripMenuItem.Text = "menu item 1"
        '
        'MenuItem2ToolStripMenuItem
        '
        Me.MenuItem2ToolStripMenuItem.Name = "MenuItem2ToolStripMenuItem"
        Me.MenuItem2ToolStripMenuItem.Size = New System.Drawing.Size(143, 22)
        Me.MenuItem2ToolStripMenuItem.Text = "menu item 2"
        '
        'MenuItem3ToolStripMenuItem
        '
        Me.MenuItem3ToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.SubMenuAToolStripMenuItem, Me.SubMenuBToolStripMenuItem, Me.SubMenuCToolStripMenuItem})
        Me.MenuItem3ToolStripMenuItem.Name = "MenuItem3ToolStripMenuItem"
        Me.MenuItem3ToolStripMenuItem.Size = New System.Drawing.Size(143, 22)
        Me.MenuItem3ToolStripMenuItem.Text = "menu item 3"
        '
        'SubMenuAToolStripMenuItem
        '
        Me.SubMenuAToolStripMenuItem.Name = "SubMenuAToolStripMenuItem"
        Me.SubMenuAToolStripMenuItem.Size = New System.Drawing.Size(152, 22)
        Me.SubMenuAToolStripMenuItem.Text = "sub menu a"
        '
        'SubMenuBToolStripMenuItem
        '
        Me.SubMenuBToolStripMenuItem.Name = "SubMenuBToolStripMenuItem"
        Me.SubMenuBToolStripMenuItem.Size = New System.Drawing.Size(152, 22)
        Me.SubMenuBToolStripMenuItem.Text = "sub menu b"
        '
        'SubMenuCToolStripMenuItem
        '
        Me.SubMenuCToolStripMenuItem.Name = "SubMenuCToolStripMenuItem"
        Me.SubMenuCToolStripMenuItem.Size = New System.Drawing.Size(152, 22)
        Me.SubMenuCToolStripMenuItem.Text = "sub menu c"
        '
        'Button1
        '
        Me.Button1.ContextMenuStrip = Me.ContextMenuStrip1
        Me.Button1.Location = New System.Drawing.Point(13, 203)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(439, 23)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Rightclick me to see same contextmenu"
        Me.Button1.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(464, 245)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.DataGridView1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ContextMenuStrip1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView
    Friend WithEvents ContextMenuStrip1 As System.Windows.Forms.ContextMenuStrip
    Friend WithEvents Menuitem1ToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents MenuItem2ToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents MenuItem3ToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents SubMenuAToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents SubMenuBToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents SubMenuCToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents Button1 As System.Windows.Forms.Button

End Class

form1.vb

Public Class Form1
    Public Sub New()
        'pre: nothing
        'post: datagridview populated with customers

        InitializeComponent()

        Me.DataGridView1.DataSource = buildDatatableWithCustomers()
    End Sub

    Private Function buildDatatableWithCustomers() As DataTable
        'pre: nothing
        'post: datatable with customers

        Dim l_dtCustomers As DataTable
        Dim l_drCustomer As DataRow

        'Build datatable
        l_dtCustomers = New DataTable("Customers")
        l_dtCustomers.Columns.Add("colCustomerId")
        l_dtCustomers.Columns.Add("colCustomerName")

        For i = 0 To 10
            l_drCustomer = l_dtCustomers.NewRow()

            l_drCustomer.BeginEdit()
            l_drCustomer("colCustomerId") = i
            l_drCustomer("colCustomerName") = "Customer " & i.ToString
            l_drCustomer.EndEdit()

            l_dtCustomers.Rows.Add(l_drCustomer)
        Next i

        Return l_dtCustomers
    End Function
End Class

peer1979  Wednesday, August 26, 2009 1:02 PM
*bump* Has anybody got a clue?
peer1979  Monday, September 07, 2009 8:41 AM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView and Custom Collection
• Bound ComboBox are automatically selecting the first item
• How to add Checkbox in DataGridView column Header
• How do i retrive a datatable from a listbox.Datasource.
• Datagirdview Scroling Problem
• Combobox problem?
• Error in tableadapter.update statement
• Always display Vertical ScrollBar in DataGridView
• Render a usercontrol
• Why HeaderCell.Style.BackColor Doesn´t work?