我正在爲.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