Problem about menustrip in windows forms
-
I have a menustrip like as a b c i wanna to add a new menuitem in this menu named as d from database and now my menustrip is looks like a b c d now m wanna to add another menuitem in this menu as e from database but now my menu shows a b c d a b c d e but i wanna tht my menu shows as a b c d e can anyone help me in it
-
I have a menustrip like as a b c i wanna to add a new menuitem in this menu named as d from database and now my menustrip is looks like a b c d now m wanna to add another menuitem in this menu as e from database but now my menu shows a b c d a b c d e but i wanna tht my menu shows as a b c d e can anyone help me in it
-
Show the code you are using; we cannot guess what is going wrong from the above.
Use the best guess
public void SubMenu(ToolStripMenuItem menuitem, string submenu) { string get_subcatagory = "select * from medicine_subcatagory where Cat_ID=(select Cat_ID from medicine_catagory where Med_Cat='" + allopathicToolStripMenuItem.Text + "')"; DataTable dt = d.getdata(get_subcatagory); foreach (DataRow dr in dt.Rows) { ToolStripMenuItem ssmenu = new ToolStripMenuItem(dr["Med_Sub"].ToString(),null, new EventHandler(ChildClick)); if (menuitem.DropDownItems.Contains(menuitem.DropDownItems[dr["Med_Sub"].ToString()])) { menuitem.DropDownItems.Remove(ssmenu); } else { menuitem.DropDownItems.Add(ssmenu); } } } thats he code i use for add submenu in menuitem
-
public void SubMenu(ToolStripMenuItem menuitem, string submenu) { string get_subcatagory = "select * from medicine_subcatagory where Cat_ID=(select Cat_ID from medicine_catagory where Med_Cat='" + allopathicToolStripMenuItem.Text + "')"; DataTable dt = d.getdata(get_subcatagory); foreach (DataRow dr in dt.Rows) { ToolStripMenuItem ssmenu = new ToolStripMenuItem(dr["Med_Sub"].ToString(),null, new EventHandler(ChildClick)); if (menuitem.DropDownItems.Contains(menuitem.DropDownItems[dr["Med_Sub"].ToString()])) { menuitem.DropDownItems.Remove(ssmenu); } else { menuitem.DropDownItems.Add(ssmenu); } } } thats he code i use for add submenu in menuitem
And what happens when you step through it in your debugger? Although, at a guess it is failing the
if
expression. BTW please indent your code and put <pre> tags round it, so it looks like:public void SubMenu(ToolStripMenuItem menuitem, string submenu)
{
string get_subcatagory = "select * from medicine_subcatagory where Cat_ID=(select Cat_ID from medicine_catagory where Med_Cat='" + allopathicToolStripMenuItem.Text + "')";
DataTable dt = d.getdata(get_subcatagory);foreach (DataRow dr in dt.Rows) { ToolStripMenuItem ssmenu = new ToolStripMenuItem(dr\["Med\_Sub"\].ToString(),null, new EventHandler(ChildClick)); if (menuitem.DropDownItems.Contains(menuitem.DropDownItems\[dr\["Med\_Sub"\].ToString()\])) { menuitem.DropDownItems.Remove(ssmenu); } else { menuitem.DropDownItems.Add(ssmenu); } }
}
Use the best guess
-
And what happens when you step through it in your debugger? Although, at a guess it is failing the
if
expression. BTW please indent your code and put <pre> tags round it, so it looks like:public void SubMenu(ToolStripMenuItem menuitem, string submenu)
{
string get_subcatagory = "select * from medicine_subcatagory where Cat_ID=(select Cat_ID from medicine_catagory where Med_Cat='" + allopathicToolStripMenuItem.Text + "')";
DataTable dt = d.getdata(get_subcatagory);foreach (DataRow dr in dt.Rows) { ToolStripMenuItem ssmenu = new ToolStripMenuItem(dr\["Med\_Sub"\].ToString(),null, new EventHandler(ChildClick)); if (menuitem.DropDownItems.Contains(menuitem.DropDownItems\[dr\["Med\_Sub"\].ToString()\])) { menuitem.DropDownItems.Remove(ssmenu); } else { menuitem.DropDownItems.Add(ssmenu); } }
}
Use the best guess
yes it always goes into else code
-
yes it always goes into else code
-
i dont know how to do it... Can u help me in it... just giv me a simple concept about how cud i check tht a particular menuitem, which is already get from database, exist over there and thn how to add new menuitem from database into that previously created menu.....
-
i dont know how to do it... Can u help me in it... just giv me a simple concept about how cud i check tht a particular menuitem, which is already get from database, exist over there and thn how to add new menuitem from database into that previously created menu.....
-
A quick glance at the documentation[^] suggests that you are testing against the wrong object type.
Use the best guess
thanks richard i solved my problem now