Solved

Programatically ContextMenuStrip in vb.net frameworks 4

Posted on 2014-07-22
1
327 Views
Last Modified: 2014-07-22
I have a contextmenu strip that I want to control completely through programming I have an external an external data source that I am looking to bind .  I am using vb.net , Winforms frameworks 4

I can put the control on the form, but after that I want to 100% through code if possible.  Any links are appreciated

chuck
0
Comment
Question by:Charles Baldo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 40213096
You can create the menus dynamically...here's a simple example:
Public Class Form1

    Private Sub ContextMenuStrip1_Opening(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening
        ContextMenuStrip1.Items.Clear() ' completely remove all menus

        ' ... access the database ...

        ' dynamically create some menus with the DB info and add them to the context menu:
        Dim mnuTSI As New ToolStripMenuItem()
        mnuTSI.Text = "Dynamic Menu"
        AddHandler mnuTSI.Click, AddressOf TSI_Click
        ContextMenuStrip1.Items.Add(mnuTSI)
    End Sub

    Private Sub TSI_Click(sender As Object, e As EventArgs)
        Dim mnuTSI As ToolStripMenuItem = DirectCast(sender, ToolStripMenuItem)
        MessageBox.Show("You clicked on: " & mnuTSI.Text)

        Select Case mnuTSI.Text
            Case "Dynamic Menu"

            Case "Something else"

        End Select
    End Sub

End Class

Open in new window


*You may not need to do this each time the Menu is opening...depends on your setup and application.  If you can do it once when the application loads that would be better.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question