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,
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,
Code:
//Dictionary<int, string> RedialedItems = new Dictionary<int, string>();
//IList<string> 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);
}