Solved

Which dynamic created Menu Item is selected

Posted on 2004-08-26
2
216 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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