c# - How to change the 'object sender'? -
i create datagridview in makedatagridview function, , maybe datagridview rightclick -> appear context menu
this sample code
public void click(object sender, mouseeventargs e) { if(e.button == mousebuttons.right) { contextmenustrip menu = new contextmenustrip(); toolstripitem insert = menu.items.add("insert"); insert.click += new eventhandler(context_menu_click); } } public void context_menu_click(object sender, eventargs e) { / * other event , printing .txt file datagridview */ }
i want print .txt file datagridview in 'context_menu_click' function. sender of click
function datagridview, context_menu_click
sender toolstripmenu.
so, how can print .txt file datagridview in context_menu_click
function?
public void context_menu_click(object sender, eventargs e) { /* other event , printing .txt file datagridview */ var item = sender toolstripitem ; if (item != null) { datagridview gv = item.tag datagridview; console.writeline(gv.name); } } private void datagridview1_mouseclick(object sender, mouseeventargs e) { if (e.button == mousebuttons.right) { contextmenustrip menu = new contextmenustrip(); toolstripitem insert = menu.items.add("insert"); insert.tag = sender; insert.click += new eventhandler(context_menu_click); menu.show(this.datagridview1.pointtoscreen(new point(e.x, e.y))); } }
you can add current datagridview
tag
toolstripitem
create
Comments
Post a Comment