Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Click Handler to Dynamically created Menu

Status
Not open for further replies.

Autosys

Programmer
Jun 1, 2004
90
GB
Hi All ..

I'm playing around with a program (not very good at it) and have written the below piece of code so far:

All of the below code is added to my main form and therefore loads when the application is started. The code basically connects to a database and then dynamically creates a Menustrip. 2 of the buttons in the menu (Home & New) will always be created and are therefore static. The rest will depend on the number of entries found in a database table (tbl_systems).

Each of the menu's will have 3 sub-menus (Names, Numbers & Configure).

The above works fine, but I would like to now make it so that I can perform certain tasks when I click on any of these menus, and my understanding is that I therefore need to create an Event Handler for this. Does this mean that my below code needs to be in a Subroutine (which I'm not entirely sure how to do)?

Any help / pointers into the right direction would be much appreciated .. or did i start off comepletely wrong?

Thanks

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

MainMenuStrip = New MenuStrip
MainMenuStrip.Items.Add("Home", Nothing)
MainMenuStrip.Items.Add("New", Nothing)


strSQL = "select SystemName from tbl_systems"

DBConnect.OpenConnection()

Dim s As String
Dim x As Integer

x = 2

Do While Not RS.EOF

s = RS.Fields(0).Value.ToString


MainMenuStrip.Items.Add(s, Nothing)

Dim cms As New ContextMenuStrip()



Dim SubMenu() As String = {"Names", "Numbers", "Configure"}


For Each menu As String In SubMenu

cms.Items.Add(menu, Nothing)

Next



Dim tsi As ToolStripMenuItem = CType(Me.MainMenuStrip.Items(x), ToolStripMenuItem)

tsi.DropDown = cms


RS.MoveNext()

Me.Controls.Add(MainMenuStrip)

x = x + 1

Loop


End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top