I want to pass buttonClick method as a parameter to the function:
we have
buttonClick:
private void iDeactivate_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
...
}
function:
private void AddItemToPopUpMenu(GridViewMenu cMenu, string cItemCaption, EventHandler cClickHandler, Image cItemImage, bool cItemBeginGroup)
{
DXMenuItem item = new DXMenuItem();
item.Caption = cItemCaption;
item.Click += new EventHandler(cClickHandler); //problem there
item.Image = cItemImage;
item.BeginGroup = cItemBeginGroup;
cMenu.Items.Add(item);
}
So can someone suggest solution?
tried:
AddItemToPopUpMenu(cMenu, iDeaActive.Caption, iDeactivate_ItemClick, null, false);
and changing function parameters to:
private void AddItemToPopUpMenu(GridViewMenu cMenu, string cItemCaption, EventHandler<ItemClickEventArgs> cClickHandler, Image cItemImage, bool cItemBeginGroup)
but then I get mistake in code where I have marked “problem there”
So is it possible to pass buttonClick method, without changing it parameters?
Edit:
As I see some wrong answers, so should say that Ihave to pass as a parameter because AddItemToPopUpMenu is called several times, every time with different methods
By the look of it,
DXMenuItem.Clickonly supplies a regularEventArgsobject and such can only work with regularEventHandlers.You’re trying to get a specialized
DevExpress.XtraBars.ItemClickEventArgsobject in your handler, and the event just doesn’t supply it.I don’t think what you’re trying to do is possible. You either need to reduce your handler so it only needs a regular
EventArgs, or you need to find a type of button whoseClickevent supplies anItemClickEventArgs.