using the string variable?

kasimacsys

Member
Joined
Jul 8, 2009
Messages
10
Programming Experience
1-3
hi,

i need to call mdi form toolstripmenuitem name using the string variable.
for ex,
mdi form is Form1.
toolstripmenuitem is customer master
if i do like that "Form1.customer master.Enabled=True" its working

but my issue is i stored customer master in a string variable like
mystring="customer master"
i need to enabled using the string variable like
Form1.mystring.enabled=True

please letme know if any one knows
 
Hello.

Have a look at Reflection, it's one way to take this one...the other would be to use the MenuStrip.Items(String) Property which takes the name of the ToolStripMenuItem.

Bobby
 
hello robert,

i tried as u told like

"Dim menuname As String = "Menu_106"
Form1.MenuStrip1.Items(menuname).Enabled = True"

but it shows the error like

"object reference not set to an instance of an object"

what should i do for that?

thanks
 
You're sure you named it that way? Remember that you have to use the Name-Property, not the Text-Property. Or is it a sub-item of another menu-item?

Though, you can also add a Breakpoint at that Form1.MenuStrip1-Line and have a closer look at the Items-Collection, to determine what objects are in there.

Bobby
 
Reg toolstripmenu

Hi,

here is the procedure

MDI(Form1)-->File (under the file menu)
||
||
Config (i assigned "config" name property is menu_101 (not text property) to String variable)
Quit
......
.......
Dim str as string="menu_101"
if i use Form1.menu_101.enabled="True" (its working)

but i neet to use the string variable like Form1.(string variable).enabled="True"

hope u understand my requirement

thanks
 
MenuStrip1.Items doesn't have a 'config' item, it has a 'file' item. The 'file' item has a 'config' item in its DropDownItems collection.
VB.NET:
FileToolStripMenuItem.DropDownItems("ConfigToolStripMenuItem").Text = "changed"
 
Dear John,

i done what u say, but it shows "object not set to an instance of an object"

my code is

Dim menuname As String = "Config"
Form1.FileToolStripMenuItem.DropDownItems("menuname").Enabled = True

thanks
 
Ok i didn't read it from beginning but according your last reply you are quoting string variable and that's why it won't work ... probably there is no sucha menu item called menuname. Rather you should refer the Config e.g.

Form1.FileToolStripMenuItem.DropDownItems("Config").Enabled = True
 
Dear Jhon,

I struggled again,

when i work under the file menu its ok.
now am moving to next menu like 'Edit'.

i can use like below..
Form1.EditToolStripMenuItem.DropDownItems("Paste" ).Enabled = True

but at runtime i dont know which toolstipmenuitem am working..
so what can i do for this time?

thanks
 
ToolStripItemCollection does have a Find method, which also has a parameter to include child collections in search. You can use this method on any of the item collections, including the root Items collection of the MenuStrip itself.
ToolStripItemCollection.Find Method (System.Windows.Forms)
 
Back
Top