flynn Posted August 23, 2006 Posted August 23, 2006 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 Quote
Cags Posted August 23, 2006 Posted August 23, 2006 Does it not support a Remove property that accepts the actual ToolStripItem rather than its index? Quote Anybody looking for a graduate programmer (Midlands, England)?
flynn Posted August 23, 2006 Author Posted August 23, 2006 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. Quote
Cags Posted August 23, 2006 Posted August 23, 2006 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. Quote Anybody looking for a graduate programmer (Midlands, England)?
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.