Hi Solar Flare,
I am getting following error for the line
"ToolStripMenuItem m = (ToolStripMenuItem)this.Co
Error 1 Cannot convert type 'System.Windows.Forms.Cont
Main Topics
Browse All TopicsHi Friends,
I am developing a windows application in VS 2008 using C#, I have a MenuStrip in my Application that contains few ToolStripMenuItems added at design time. When I run my application user need to login using Username and password which is verified against a record in Database.
Before Login when application loads I remove all ToolStripMenuItems using ".Clear()" e.g.
this.mnusMain.Items.Clear(
(mnusMain is a name of MenuStrip)
after successfully login those items are restored e.g.
ToolStripMenuItem tmp;
tmp = tsmiPatientCare;
this.mnusMain.Items.Add(tm
tmp = tsmiManage;
this.mnusMain.Items.Add(tm
tmp = tsmiTools;
this.mnusMain.Items.Add(tm
tmp = tsmiHelp;
this.mnusMain.Items.Add(tm
(tsmiPatientCare, tsmiManage, tsmiTools, tsmiHelp are ToolStripMenuItems and these names are given at Design Time)
Now what I am trying to do is, rather restoring all ToolStripMenuItems, a user will get a datatable filled with the name of ToolStripMenuItems which he required and I want to loop through the datatable and use those values as name of ToolStripMenuItems to restore.
I am trying following code but it never works :
DataRow[] temp = Login.dsLogin.Tables["User
this.mnusMain.Items.Clear(
ToolStripMenuItem tmp;
foreach (DataRow dr in temp)
{
tmp =dr["ItemName"].ToString()
this.mnusMain.Items.Add(tm
}
Suppose "dr["ItemName"].ToString()
Thanks,
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi mate,
as a solution for your scenario I would use the attached code.
Note that you can also have multiple ToolStrips and hide/show them as needed. Imagine having one ToolStrip for the login and another for the application.
I have 3 buttons on my test form and these are their click events:
btnRemove_Click
Remo
btnAdd_Click
Adds
btnAddByName_Clic
Adds the buttons to the toolstrip based on a harcoded string List.
You can have whatever you want to hold this list of items names.
Cheers!
Alex
Business Accounts
Answer for Membership
by: Solar_FlarePosted on 2009-05-20 at 21:48:24ID: 24438176
You are dealing with objects of type ToolStripMenuItem in your first bit of code and adding them to your toolstrip, but in the second you are dealing with strings and adding those strings to the toolstrip...
In order to find a control on your form by a given name you will need to use the Find method of a controlcollection, so I think you want to do something like this:
Select allOpen in new window