Hi
I am looking for some help in adding events to dynamic contextmenu.I want to rise the click event for each of the menu ite
that I am creating.

Below is my code for adding dynamic context menu

System.Windows.Forms.MenuItem MnuItem
MnuItem= new System.Windows.Forms.MenuItem()
MnuItem.Text = comboBox1.Text;
cmFavorites.MenuItems.Add(cmFavorites.MenuItems.Count,MnuItem)

can someone help me with the sample lines of code ,how to add the events for the dynamic menu
Thanks for your help in advanc
Priya

Re: How to add events to dynamic contextmenu ? by Wiktor

Wiktor
Fri May 07 09:50:44 CDT 2004

>
> System.Windows.Forms.MenuItem MnuItem;
> MnuItem= new System.Windows.Forms.MenuItem();
> MnuItem.Text = comboBox1.Text;

MnuItem.Click += new EventHandler( method_name );

where

void method_name( object sender, EventArgs e )
{
...
}

Regards,
Wiktor Zychla



Re: How to add events to dynamic contextmenu ? by anonymous

anonymous
Fri May 07 10:46:02 CDT 2004

Thanks I am able to get the click event working.One more question in this context
How will I reference the object name inside the click event,since I am creating the context menu dynamically
I cannot reference it using MnuItem.Text any more

System.Windows.Forms.MenuItem MnuItem
MnuItem= new System.Windows.Forms.MenuItem()
MnuItem.Text = comboBox1.Text
cmFavorites.MenuItems.Add(cmFavorites.MenuItems.Count,MnuItem)
MnuItem.Click += new EventHandler( MnuItem_Click )

private void MnuItem_Click( object sender, EventArgs e

//How will I reference MnuItem.Text here.


Thanks for your help
Regards
Priy


Re: How to add events to dynamic contextmenu ? by anonymous

anonymous
Fri May 07 11:31:05 CDT 2004

Thanks I found the solution
For other who is looking for an answer ,here is how it can be done
private void MnuItem_Click( object sender, EventArgs e

MenuItem mi = (MenuItem)sender
MessageBox.Show(mi.Text)