0

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!

Landin Martens
  • 3,283
  • 12
  • 43
  • 61

1 Answers1

1

The BindingSource doesn't have a "parent" control. In fact, the BindingSource isn'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 a BindingSource is defined in a Binding object which is contained in the bound control's DataBindings property.

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.

Peter Ritchie
  • 35,463
  • 9
  • 80
  • 98