Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi friends,

File
new
exit

i try to do Dynamic menu strip in windows form,.

the first parent is permanently fixed in form. the child are generated regarding the database.

i just created a data table with Name, ParentId, image, eventhandler.

in windows form code,..

string MyConString = "server=192.168.1.100;User Id=root;Persist Security Info=True;database=cms";
            MySqlConnection connection = new MySqlConnection(MyConString);
            MySqlCommand command = connection.CreateCommand();
            MySqlDataReader Reader;
            command.CommandText = "select * from menu_details";
            connection.Open();
            Reader = command.ExecuteReader();
            while (Reader.Read())
            {
                string a = Convert.ToString(1);
                if (Reader[5].ToString() == a)
                {
                    string j = @"D:\cms-image\";
                    string k = Reader[13].ToString();
                    tsm_File.DropDownItems.Add(Reader[1].ToString(), Image.FromFile(j + k), new EventHandler(newToolStripMenuItem_Click));
                }                
            }
            connection.Close();


In that i reach half,. but i wanna change EventHandler for each,. is it possible?. if possible means how.?
Posted

1 solution

Ideally, you should be able to use the same event for all menu items.
Just check the send object and write code based on the sender (in the menu click handler).
 
Share this answer
 
Comments
Sagotharan Jagadeeswaran 18-May-11 7:15am    
ya its working. i was think about only change event handling. but sender option is perfect. thank u very much.

private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
string s = Convert.ToString(sender);
if (s == "new")
{
New u = new New();
u.ShowDialog(this);
}
}
Abhinav S 18-May-11 7:40am    
You are welcome.
Sergey Alexandrovich Kryukov 18-May-11 15:19pm    
As simple as that, a 5.
--SA
Abhinav S 19-May-11 0:01am    
Thank you SA.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900