954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to enable/disable ToolStripMenuItem Name using String variable

hi!,

i have MDI form(Form1) which contain some toolstripmenu item.
for example menu_101.

if i do "Form1.menu_101.enabled=True" its working fine.

my problem is i have a string variable like "menuname" which contain
like
menuname=menu_101

i need to enable or disable using this string variable like
"Form1.menuname.enabled=True"

please anyone knows let me know...
thanks

kasimacsys
Newbie Poster
4 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

hmm i have solved that problem in the past like this

Dim menuStrip As Contexmenu= DirectCast(Form1.Controls.Find(menuname, True)(0), Contexmenu)
menuStrip.Enable=True
GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 

hmm i have solved that problem in the past like this

Dim menuStrip As Contexmenu= DirectCast(Form1.Controls.Find(menuname, True)(0), Contexmenu)
menuStrip.Enable=True


I tried like what u give
' Dim menuStrip As ContextMenu = DirectCast(Form1.Controls.Find(menuname, True)(0), ContextMenu)
menuStrip.Enabled = True '

but it shows the error like below

"value of type 'System.Windows.Forms.Control' cannot be
converted to 'System.Windows.Forms.ContextMenu'".

please tell me what should i do?

thanks

kasimacsys
Newbie Poster
4 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

just checked it again. sorry was my fault. contexmenus arent controls

here is a working example

Dim menustrip As String = "ContextMenuStrip1"

        For Each cntrl As Control In Me.components.Components
            If cntrl.Name = menustrip Then
                'do what ever you need to do 
                Exit For
            End If
        Next
GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 

I have a Menustrip and the MenuStrip contain 9 items.
In each item contain subitem.
I want to disable sum subitem when I select from database to compare with the subitem name.
how can I do?

bunthom
Newbie Poster
1 post since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You