Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Finding an menuItem in the MenuContext

Finding an menuItem in the MenuContext

Scheduled Pinned Locked Moved C#
databasevisual-studio
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    steve_rm
    wrote on last edited by
    #1

    Hello, VS 2008 I am adding menuItems to a menuContext. However, I only want to allow a maximum of 10 menuItems to be added. This works ok. However, if a menuItem is about to be added. Which is already contained in the menuContext. Then I want to get the index of this, so that I can remove it. And add in index 0. The idea is to add phone numbers, and display the most recent one that was dialed. This is why I am adding at index 0. However, if a phone number is already in the menuContext then I need to find it so that I can remove it. I have tried using the contains, Find, and IndexOf methods, but no use. See comments below. I have tried using the Dictionary and IList to keep track of the items. However, this doesn't seem be the right solution either. Many thanks for any suggestions, //Dictionary<int,> RedialedItems = new Dictionary<int,>(); //IList dialedNumbers; //Add a new number to the redial history public void AddToRedialHistory(string number) { this.shortcutRedialMenu = new MenuItem(); this.shortcutRedialMenu.Text = number; //Trying to get an index of the value I am looking for. //int index = this.ctxRedialMenu.MenuItems.IndexOf(shortcutRedialMenu); //index = this.ctxRedialMenu.MenuItems.IndexOfKey("1"); //index = Convert.ToInt16(this.ctxRedialMenu.MenuItems.Contains(shortcutRedialMenu)); //Only keep redial history for a maximum of 10 numbers. //if greater then 10, remove the last one index 10. int count = this.ctxRedialMenu.MenuItems.Count; if (count > 9) { this.ctxRedialMenu.MenuItems.RemoveAt(9); } //Add to the zero index so that all the number are displayed //in reverse order. Most recent displayed at the top. this.ctxRedialMenu.MenuItems.Add(0, shortcutRedialMenu); //Adding them to the dictionary. //this.RedialedItems.Add(this.shortcutRedialMenu.Index, shortcutRedialMenu.Text); //Add event handler for clicking on the shortcut menu. this.shortcutRedialMenu.Click += new EventHandler(this.ShortCutRedial_Clicked); }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups