C
Christian Ahrenkiel
Hi!
I've got a submenu in my ContextMenu, which is generated during
runtime.
I'm not sure about handling the Click-Event in dynamic menues.
I'm abled to fire the Click-Event for all MenuItems, but cannot
distinguish which MenuItem was clicked.
This is just an example how I'm handling it (very simplyfied for this
posting - i hope there are no confusing errors):
// Having an array with strings
for(int i=0; i < myarray.Length; i++)
{
addSubmenu(myarray);
}
// Each element shall be a MenuItem
private void addSubmenu(string menu)
{
// Creating a new temporarily MenuItem
MenuItem mniTemp = new MenuItem();
mniTemp.Text = menu;
// Adding this MenuItem to my menu
this.mniMenu.MenuItems.Add(mniTemp);
// Adding an EventHandler
mniTemp.Click += new EventHandler(tmp_Click);
}
// The EventHandler - it fires for all generated MenuItems
private void tmp_Click(object sender, EventArgs e)
{
// How can I distinguish _here_ _which_ MenuItem was hit?
}
Are there any other possibilities? Maybe with ArrayLists (analogous to
ArrayLists and Comboboxes)?
Christian
I've got a submenu in my ContextMenu, which is generated during
runtime.
I'm not sure about handling the Click-Event in dynamic menues.
I'm abled to fire the Click-Event for all MenuItems, but cannot
distinguish which MenuItem was clicked.
This is just an example how I'm handling it (very simplyfied for this
posting - i hope there are no confusing errors):
// Having an array with strings
for(int i=0; i < myarray.Length; i++)
{
addSubmenu(myarray);
}
// Each element shall be a MenuItem
private void addSubmenu(string menu)
{
// Creating a new temporarily MenuItem
MenuItem mniTemp = new MenuItem();
mniTemp.Text = menu;
// Adding this MenuItem to my menu
this.mniMenu.MenuItems.Add(mniTemp);
// Adding an EventHandler
mniTemp.Click += new EventHandler(tmp_Click);
}
// The EventHandler - it fires for all generated MenuItems
private void tmp_Click(object sender, EventArgs e)
{
// How can I distinguish _here_ _which_ MenuItem was hit?
}
Are there any other possibilities? Maybe with ArrayLists (analogous to
ArrayLists and Comboboxes)?
Christian