ToolStripMenuItem question

flynn

Regular
Joined
Jul 28, 2005
Messages
59
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).
Code:
        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
 
Cags said:
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.
 
Back
Top