Results 1 to 7 of 7

Thread: [RESOLVED] Help with ContextMenuStrip on DataGridView

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    85

    Re: Help with ContextMenuStrip on DataGridView

    Hi Folks,

    I sure would appreciate some help. I've searched VBWire and MSDN looking for examples. I'm not yet experienced enough to put it all together.

    Thanks Robo

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    85

    Re: Help with ContextMenuStrip on DataGridView

    Ok I think I have the ContextMenuStrip menuitem right clicks figured out. Comments?

    I set my ContextMenuStrip = DataGridView.ContextMenuStrip but my menu comes up anywhere on the form. It should be restricted to DGV correct? Any insights?

    Thanks

    Code:
    Public Class Form1
        Private CMS As ContextMenuStrip
        Private TSM1 As ToolStripMenuItem
        Private TSM2 As ToolStripMenuItem
        Private TSM3 As ToolStripMenuItem
        Private TSM4 As ToolStripMenuItem
        Private DGV As DataGridView
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Call CMSLoad()
        End Sub
    
        Private Sub CMSLoad()
            CMS = New ContextMenuStrip
            DGV = New DataGridView
            TSM1 = New ToolStripMenuItem
            TSM2 = New ToolStripMenuItem
            TSM3 = New ToolStripMenuItem
            TSM4 = New ToolStripMenuItem
            '
            CMS.Items.AddRange(New System.Windows.Forms.ToolStripMenuItem() {TSM1, TSM2, TSM3, TSM4})
            '
            TSM1.Text = "First"
            TSM2.Text = "Second"
            TSM3.Text = "Third"
            TSM4.Text = "Forth"
            TSM1.Name = "First"
            TSM2.Name = "Second"
            TSM3.Name = "Third"
            TSM4.Name = "Forth"
            '
            DGV.ContextMenuStrip = CMS
            '
            AddHandler TSM1.Click, AddressOf TSM1_Click
            AddHandler TSM2.Click, AddressOf TSM2_Click
            AddHandler TSM3.Click, AddressOf TSM3_Click
            AddHandler TSM4.Click, AddressOf TSM4_Click
            '
            ContextMenuStrip = CMS
        End Sub
    
        Private Sub TSM1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Debug.Print("ToolStripMenu1")
        End Sub
    
        Private Sub TSM2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Debug.Print("ToolStripMenu2")
        End Sub
    
        Private Sub TSM3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Debug.Print("ToolStripMenu3")
        End Sub
    
        Private Sub TSM4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Debug.Print("ToolStripMenu4")
        End Sub
    End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width