ContextMenu Item not calling function

J

Jasim

hi everyone,
i have a problem with context menu's. actually what i'm
trying to do is to call the same function with the parent
item when clicked as well as sub items. it works for sub
menu item but fails for the parent menu item.

can someone please help me with this ....

thanx
-jasim

i'm attaching the code as well.

****************** Code ***********************

public void AddTAMenu()
{
try
{

DataSet ds = new DataSet();

ds.ReadXml("D:TA.xml");

DataTable dt1 = new DataTable();
dt1 = ds.Tables["TAClass"];

foreach (DataRow dr1 in
dt1.Rows)
{
string criteria;
criteria
= "TAClassID=" + dr1.ItemArray.GetValue(0).ToString();
MenuItem ClassItem
= new MenuItem(dr1.ItemArray.GetValue(1).ToString(),new
EventHandler(SelectValue));
foreach (DataRow
dr2 in
ds.Relations["class_generic"].ChildTable.Select(criteria))
{

ClassItem.MenuItems.Add(new MenuItem
(dr2.ItemArray.GetValue(2).ToString(),
new EventHandler(SelectValue)));

TANamepopUpMenu.MenuItems.Add
(dr2.ItemArray.GetValue(2).ToString(),new
EventHandler(SelectValue));
}

TAClasspopUpMenu.MenuItems.Add(ClassItem);
}
}
catch (Exception exp)
{

throw new Exception
("Search.AddTAMenu : " + exp.Message);
}
}



private void SelectValue(object sender, EventArgs e)
{
MenuItem miClicked = (MenuItem)
sender;
string item = miClicked.Text;
txtTA.Text =
miClicked.Text.ToString();
}

..
 
J

Joe White

Parent menu items act differently from child menu items. Clicking a
parent item will simply open its child menu, and will not fire any
events. This is the way Windows menus are designed, so you can't change it.

If you want to accept clicks from the parent menu item, then (a) you'll
have a non-standard UI that may confuse your users, and (b) you'll have
to go with a third-party control to provide the feature, instead of
using a ContextMenu. Unfortunately, I don't know any good third-party
menu/toolbar systems for .NET (though I can recommend an excellent one
for Delphi...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top