Solved

Programatically ContextMenuStrip in vb.net frameworks 4

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 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

13 Experts available now in Live!

Get 1:1 Help Now