Solved

Which dynamic created Menu Item is selected

Posted on 2004-08-26
2
223 Views
Last Modified: 2010-04-15
Ok I read a directory and determine how many files match my search criteria, then I add the names of these files to a menu. The idea being that when the item is selected in the menu that I will load it.

I was able to figure out a way to add the menu in a loop, but I can't figure out a way to find out which of these dynamic menus has been selected.

for(int i;i<#offiles;i++)
EventHandler ev = new EventHandler(this.Item_clicked);
File.MenuItems.Add(new MenuItem(strfilename, ev));

private void Item_clicked(object sender, EventArgs e)
{
     ??? How do I figure out which item was selected ??
}
0
Comment
Question by:toby_lang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
eternal_21 earned 50 total points
ID: 11909369
If the method is called by the MenuItem.Click event, then the "sender" parameter will be the MenuItem, so you could use the code:

  if(sender is System.Windows.Forms.MenuItem)
  {
    System.Windows.Forms.MenuItem menuItem;
    menuItem = (System.Windows.Forms.MenuItem)sender;

    // Process code here, dependant of menuItem, eg: switch(menuItem.Text)...
  }
  else
  {
    //Item_clicked sender parameter was some other type of object
  }
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question