Solved

Which dynamic created Menu Item is selected

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

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…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now