I am creating an Extension method for the .net BindingSource object. Currently the method needs a Control passed in (this Control is the “main” Control which is normally a UserControl or a Form).
I would like how ever, to not have to pass this “parent” Control in. Is there a way to find a BindingSource parent Control? I know there is a Container but that does not help me or at least I don’t think it does.
Currently you call this method like below (C# UserControl):
//'new Object()' would be the data source
BindingSourceControlName.ExtMethodName(This, new Object());
I would like to dynamically get the parent Control from the BindingSource so that I could call the method like below (C# UserControl):
//'new Object()' would be the data source
BindingSourceControlName.ExtMethodName(new Object());
Is this even possible, maybe using reflection? Thank you for reading!
The
BindingSourcedoesn’t have a “parent” control. In fact, theBindingSourceisn’t bound to anything, like a control. It is the source of data, for use in data binding. It can be bound to by many targets. What is bound to aBindingSourceis defined in aBindingobject which is contained in the bound control’sDataBindingsproperty.i.e. you’re looking at it in the wrong direction. You can find the data bindings for a particular control, but you can’t find that information from the
BindingSource.Maybe if you describe what you’re trying to do, someone can provide some detail on that.