-
March 2nd, 2010, 12:53 PM
#1
A menustrip
Two weeks ago I have posted a question about menu driven menustip. I didn't really get solution to my questions, but I got something to start fo- the main idea. But now I am stuck to it again:
I got the following code from a member fromt his forum:
Code:
testDBDataContext db = new testDBDataContext();
List<tablename> lst = (from table in db.lesons
select table).ToList();
foreach (tablename tbl in lst)// this will populate all your menuitems
{
ToolStripItem itm = new MenuItem(tbl.name); //Create a new menuitem
itm.Click += new EventHandler(itm_Click); //assign event handlers for the OnClick event
this.MenuItem.Add(itm);
}
But I get the following errors:
Error 2 The name 'itm_Click' does not exist in the current context C:\Users\Lost\Documents\Visual Studio 2008\Projects\testproject\testproject\Teacher\Teachermain.cs 22 47 testproject
Error 3 'WindowsFormsApplication1.Teachermain' does not contain a definition for 'MenuItem' and no extension method 'MenuItem' accepting a first argument of type 'WindowsFormsApplication1.Teachermain' could be found (are you missing a using directive or an assembly reference?) C:\Users\Lost\Documents\Visual Studio 2008\Projects\testproject\testproject\Teacher\Teachermain.cs 23 22 testproject
Also I need it to populate a menuStrip1, and I am not sure that it is really doing this.
I have searched how to do it for hours, but I couldn't get anything to work.
I awfully need this and I will be really happy if someone tells me how it sohuld be rewritten.
Thanks in advance!
Last edited by lost_bg; March 4th, 2010 at 11:39 AM.
-
March 2nd, 2010, 11:01 PM
#2
Re: A menustrip
The errors you are getting are pretty catastrophic and not necessarily related to the code you have supplied. I suggest you remove the code until you get the programme to compile and then gradually add a bit at a time, checking for errors at each stage.
You need to show more code and also tell us what controls you have on your form. Also can you post code between [C0DE] and [/C0DE] tags (replace the ZERO with the letter o) so that it is more readable.
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
-
March 3rd, 2010, 03:49 AM
#3
Re: A menustrip
Well the only thing I have in the form is this. I was adding it gradually and the program was compiling with no problem at all. I am pretty sure that this thing is causing the errors...
-
March 4th, 2010, 08:36 AM
#4
Re: A menustrip
UP! This is something really important for me. I can't belive that noone knows anything about it!
-
March 4th, 2010, 09:58 AM
#5
Re: A menustrip
Does the db.lesons collection have a field called name?
-
March 4th, 2010, 11:38 AM
#6
Re: A menustrip
Oh yeah, sorry about that, I got this fixed just when I posted this...thought I updated the error list.
I think the whole thing here is a mess:
Code:
{
ToolStripItem itm = new MenuItem(tbl.name); //Create a new menuitem
itm.Click += new EventHandler(itm_Click); //assign event handlers for the OnClick event
this.MenuItem.Add(itm);
}
Where in this thing I should specify that i want the records added to menuStrip1 in its testToolStripMenuItem ?
I have searched for this things for days and couldn't find anything that could help me fix it / or rewrite it and atm I am desperate....
Last edited by lost_bg; March 4th, 2010 at 11:46 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|