Solved

Programatically ContextMenuStrip in vb.net frameworks 4

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

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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