CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: A menustrip

  1. #1
    Join Date
    Feb 2010
    Posts
    25

    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.

  2. #2
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

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

  3. #3
    Join Date
    Feb 2010
    Posts
    25

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

  4. #4
    Join Date
    Feb 2010
    Posts
    25

    Re: A menustrip

    UP! This is something really important for me. I can't belive that noone knows anything about it!

  5. #5
    Join Date
    Dec 2008
    Posts
    144

    Re: A menustrip

    Does the db.lesons collection have a field called name?

  6. #6
    Join Date
    Feb 2010
    Posts
    25

    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
  •  





Click Here to Expand Forum to Full Width

Featured