Source control is null when accessing from a sub context menu item in C# -
i trying change color of button when click on sub menu item (colors > red) context menu strip.
this code attached user defined amount of buttons. figure out button trying change, trying go sub item source control such: sender > owner tool strip > owner menu > source control.
my code:
private void redtoolstripmenuitem_click(object sender, eventargs e) { toolstripitem subitem = sender toolstripitem; if (subitem == null) return; toolstripitem mainitem = subitem.owneritem toolstripitem; if (mainitem == null) return; contextmenustrip menustrip = mainitem.owner contextmenustrip; if (menustrip == null) return; datagridview datagridview = menustrip.sourcecontrol datagridview; if (datagridview == null) return; //null here messagebox.show(datagridview.name); }
from i've found on google, appears bug. there workarounds this?
Comments
Post a Comment