Solved

Programatically ContextMenuStrip in vb.net frameworks 4

Posted on 2014-07-22
1
314 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:charlesbaldo
1 Comment
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now