Solved

Programatically ContextMenuStrip in vb.net frameworks 4

Posted on 2014-07-22
1
324 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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syntax Issue with SSIS module 26 105
JSON Deserialize issue 6 26
System.net.Sockets Error 5 28
Why use this lambda? 12 39
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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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