المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Dynamic Menu Creation Problem



C# Programming
08-19-2009, 11:22 PM
I am trying to teach myself C# and I have started writing a web browser based on mozilla gecko. Right now I am working on storing and retrieving bookmarks from an xml document.

I can save and read the bookmarks just fine. However in order to see a bookmark I just added I must exit the program and restart it. I have tried calling the function that populates the menu after the new bookmark is written to the xml file but it runs and loads everything but the new bookmark.

Below is the code I use to populate the menus.




public void PopulateBM()


{


string filename = "bookmarks.xml";


if(File.Exists(filename))


{


XmlDocument xmldoc = new XmlDocument();


xmldoc.Load(filename);


XmlNodeList xmlnode = xmldoc.GetElementsByTagName("Bookmark");


for (int i = 0; i < xmlnode.Count; i++)


{


ToolStripMenuItem item = new ToolStripMenuItem();


item.Text = xmlnode[i].FirstChild.InnerText;


item.Tag = xmlnode[i].LastChild.InnerText;


item.ToolTipText = xmlnode[i].LastChild.InnerText;


item.Click += new EventHandler(this.item_Click);


this.bookmarksToolStripMenuItem.DropDownItems.Insert(3,item);


}


}


}