Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am using the new ToolStripMenuItem in .Net 2.0, which replaces MenuItem. MenuItem has an "Index" property, but ToolStripMenuItem does not. Is there a way to determine the index of the currently selected menu item from within a "Click" event?

 

What I'm trying to accomplish is to remove a menu item when it's clicked, then put this same menu item at the top of the menu (the menu is a Most Recently Used list).

       private void OnMRUClicked(object sender, EventArgs e)
       {
               ToolStripItem item = (ToolStripItem)sender;

                // remove the menu item from its current location...
                mruList.RemoveAt(item.Index); // <--- error, no Index property
                // ...and add it to the top of the MRU menu
                mruList.Insert(0, mru);                        
       }

 

tia,

flynn

Posted
Does it not support a Remove property that accepts the actual ToolStripItem rather than its index?
Anybody looking for a graduate programmer (Midlands, England)?
Posted
Does it not support a Remove property that accepts the actual ToolStripItem rather than its index?

 

It does, but it expects a generic object as the parameter.

 

Instead, I'll just run a for loop through the array until I find the one I need to remove. Should be fairly quick since there should only be 10 menu items at most.

Posted
It shouldn't matter that it expects a generic object as a parameter, have you tried calling mruList.Remove(sender) or even mruList.Remove(item) both should work.
Anybody looking for a graduate programmer (Midlands, England)?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...