MainMenu MMenu = new MainMenu(); DataTable DT_Menu = GetDataTable(); foreach (DataRow DR in DT_Menu.Rows) { if (Convert.ToBoolean(DR["M_Header"]) == true) { MenuItem MItem = new MenuItem(); MItem.Name = DR["M_Name"].ToString(); MItem.Text = DR["M_Text"].ToString(); MMenu.MenuItems.Add(MItem); } else { MenuItem CMItem = new MenuItem(); CMItem.Name = DR["M_Name"].ToString(); CMItem.Text = DR["M_Text"].ToString(); MenuItem ExistMnu = new MenuItem(); ExistMnu = (MenuItem) MMenu.MenuItems[DR["M_Parent"].ToString()]; if (ExistMnu != null) { ExistMnu.MenuItems.Add(CMItem); } } } Menu = MMenu; } public DataTable GetDataTable() { DataTable DT = new DataTable("MENU"); DataColumn Pmry2 = new DataColumn("M_Parent", typeof(string)); Pmry2.Unique = false; DataColumn Pmry3 = new DataColumn("M_Name", typeof(string)); Pmry3.Unique = true; DT.Columns.Add(Pmry2); DT.Columns.Add(Pmry3); DT.Columns.Add("M_Text", typeof(string)); DT.Columns.Add("M_Header", typeof(bool)); DataColumn[] myPrimaryKeyColumns = new DataColumn[2]; myPrimaryKeyColumns[1] = DT.Columns["M_Name"]; DT.PrimaryKey = myPrimaryKeyColumns; DT.Rows.Add("" , "File", "FILE", true); DT.Rows.Add("File", "New", "NEW", false); DT.Rows.Add("New", "Project", "PROJECT", false); return DT; } } }
MenuItem
MenuItems
MenuItem.MenuItems.Add(existingMenuItem)
MainMenu MMenu = new MainMenu(); DataTable DT_Menu = GetDataTable(); MenuItem MItem = new MenuItem(); foreach (DataRow DR in DT_Menu.Rows) { if (Convert.ToBoolean(DR["M_Header"]) == true) { MItem = new MenuItem(); MItem.Name = DR["M_Name"].ToString(); MItem.Text = DR["M_Text"].ToString(); MMenu.MenuItems.Add(MItem); } else { MenuItem MItemChild = new MenuItem(); MItemChild.Name = DR["M_Name"].ToString(); MItemChild.Text = DR["M_Text"].ToString(); MMenu.MenuItems.Add(MItemChild); } } Menu = MMenu; }
ExistMnu.MenuItems.Add(CMItem)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)