Click to See Complete Forum and Search --> : A menustrip


lost_bg
March 2nd, 2010, 11:53 AM
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:



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!

rliq
March 2nd, 2010, 10:01 PM
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 and tags (replace the ZERO with the letter o) so that it is more readable.

lost_bg
March 3rd, 2010, 02:49 AM
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...

lost_bg
March 4th, 2010, 07:36 AM
UP! This is something really important for me. I can't belive that noone knows anything about it!

CreganTur
March 4th, 2010, 08:58 AM
Does the db.lesons collection have a field called name?

lost_bg
March 4th, 2010, 10:38 AM
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:

{
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....