我正在为.net BindingSource
对象创建一个Extension
方法。目前该方法需要通过一个Control
(此Control
是“主”Control
,通常是UserControl
或Form
)。C#从BindingSource扩展方法中获取父控件(UserControl或Form)
我想永远不用通过这个“父母”Control
英寸。有没有办法找到BindingSource
父母Control
?我知道有一个Container
但这并没有帮助我,或者至少我不认为它确实如此。
目前你调用像下面这种方法(C#UserControl
):
//'new Object()' would be the data source
BindingSourceControlName.ExtMethodName(This, new Object());
我想从BindingSource
所以动态获取父Control
,我可以打电话给像下面的方法(C#UserControl
):
//'new Object()' would be the data source
BindingSourceControlName.ExtMethodName(new Object());
这是甚至可能的,也许使用反射?感谢您的阅读!
你是否自己实例化BindinSource(将其分配给BindingSourceControlName),还是使用Designer来创建绑定源? – 2012-07-31 16:46:29
使用设计器拖放BindingSource。 – 2012-07-31 16:58:47