Hi Experts,
I am new to this Forum !!!!
I have a requirement where I need to dynamically load the Menu from Table, in C# Windows
Application based on the Language Selected from the Combo Box.
My Attempt:
Table Definition:
create table menu_table(
MAIN_MNU varchar(50),
MAIN_MNU_GRP int,
CHILD_MNU varchar(50),
CHILD_MNU_GRP int,
LANG varchar (50))
01 | private void loadMenu( string _language) |
03 | string connectionString = "Data Source =..." ; |
05 | string sql = "SELECT MAIN_MNU,MAIN_MNU_GRP,CHILD_MNU,CHILD_MNU_GRP FROM MENU_TABLE WHERE LANG='" + _language + "'" ; |
06 | SqlConnection connection = new SqlConnection(connectionString); |
07 | SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection); |
08 | DataSet ds = new DataSet(); |
10 | dataadapter.Fill(ds, "Menu Table" ); |
13 | MenuItem[] mnuItem = new MenuItem[ds.Tables[0].Rows.Count]; |
14 | if (ds.Tables[0].Rows.Count > 0) |
17 | for ( int j = 0; j < ds.Tables[0].Rows.Count; j++) |
19 | string s = ds.Tables[0].Rows[j].ItemArray[0].ToString(); |
20 | mnuItem[j] = new MenuItem(s, new System.EventHandler(mnuClick)); |
22 | if (ds.Tables[0].Rows[j].ItemArray[1].ToString() == "0" ) |
24 | this .mnuMainMenu.MenuItems.Add(ds.Tables[0].Rows[j].ItemArray[0].ToString()); |
26 | if (ds.Tables[0].Rows[j].ItemArray[3].ToString() == "1" ) |
28 | int father = Convert.ToInt32(ds.Tables[0].Rows[j].ItemArray[1].ToString()); |
30 | this .mnuMainMenu.MenuItems[father].MenuItems.Add(ds.Tables[0].Rows[j].ItemArray[2].ToString()); |
36 | this .Menu = mnuMainMenu; |
40 | private void mnuClick( object sender, System.EventArgs e) |
42 | MenuItem item = (MenuItem)sender; |
43 | string mess = item.Text.ToString(); |
44 | MessageBox.Show( "You clicked menu " + mess); |
The problem with this is,The event for the Button is not triggered when I press the Menu Item.
I can't able to Solve this. Kindly help me to solve this Issue.
Thanks & Regards,
Shanklar