Dynamic Creation of MenuStrip - VB
Dynamic Creation of MenuStrip - VB
NET - CodeProject
home articles quick answers discussions features community help Search for articles, questions, tips
Implementing Menustrip dynamically from database, the menu names and order will be through backend.
Introduction
I came up with the problem of creating an application that was driven according to user rights. I thought of
implementing the menus to be driven through BackEnd. All the menu names and the form (formname) to open when
the child menu was clicked, come from the table. To implement menus, I used MenuStrip from VB.NET.
Sample Code
The code below will have a variable like iUserAccessMode, which in turn tells us about the user access level (Look
into the Excel sheet which has been attached and look into the Access Tab in the Excel sheet). The Menus will be
loaded according to User Access Level.
If mnRd.HasRows Then
mnMenu = New MenuStrip
While mnRd.Read
mnMenu.Items.Add(mnRd(0).ToString, Nothing, New System.EventHandler(
AddressOf MainMenu_OnClick))
Me.Controls.Add(mnMenu)
End While
End If
mnRd.Close()
End Sub
http://www.codeproject.com/Articles/19223/Dynamic-Creation-Of-MenuStrip-VB-NET 1/4
8/27/2014 Dynamic Creation Of MenuStrip - VB.NET - CodeProject
This function creates child menus when the parent menu is created.
Points of Interest
I came up with the problem of converting the formname which I get from SQL as string to FORM object. This
function helps in converting the string object formName, which is returned from SQL into object of type Form:
History
17th June, 2007: Initial post
License
This article, along with any associated source code and files, is
licensed under The Code Project Open License (CPOL)
Share
EMAIL
No Biography provided
Bad Programmer
United Kingdom
Article Top
Search Comments Go
Profile popups Spacing Compact Noise Medium Layout Normal Per page 50 Update
Re: Object reference not set to an instance of an object. TheXeon1981 12-Nov-11 5:26
MainMenu twice click from first form load Member 2728683 24-Jul-09 1:28
Re: MainMenu twice click from first form load Juan Camilo Arboleda 1-Aug-09 16:10
Re: MainMenu twice click from first form load Mark Denson 16-Nov-09 6:58
Re: MainMenu twice click from first form load wallaces528 16-Nov-09 16:52
Re: Result listed by vertical, not horizontal Bad Programmer 15-Jan-09 20:51
Re: open dynamic form in MDI window Bad Programmer 5-Nov-08 1:13
Re: open dynamic form in MDI window Mark Denson 16-Nov-09 7:01
http://www.codeproject.com/Articles/19223/Dynamic-Creation-Of-MenuStrip-VB-NET 3/4
8/27/2014 Dynamic Creation Of MenuStrip - VB.NET - CodeProject
thakur
Use the 'new' keyword to create an object instance. keonj 26-Jun-07 12:00
Re: Use the 'new' keyword to create an object instance. Bala J 30-Jun-07 11:17
Re: Use the 'new' keyword to create an object instance. Dustin Klinkenberg 20-Aug-08 7:53
Re: Use the 'new' keyword to create an object instance. Alicealiciasawarak 28-Mar-11 19:00
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
Permalink | Advertise | Privacy | Mobile Layout: fixed | fluid Article Copyright 2007 by Bad Programmer
Web04 | 2.8.140826.1 | Last Updated 24 Aug 2008 Everything else Copyright © CodeProject, 1999-2014
Terms of Service
http://www.codeproject.com/Articles/19223/Dynamic-Creation-Of-MenuStrip-VB-NET 4/4