changing a databinding

Posted by Freddy Boisseau on 10-Nov-2008 14:25

Is there a way to determine what controls are bound to a binding source? Once you have determine that is there a way to move the control from that binding source to another, keeping the parameters set by the programmer for the first binding source.

All Replies

Posted by Peter Judge on 10-Nov-2008 14:48

Is there a way to determine what controls are bound

to a binding source?

I assume you mean in the control itself? I don't believe so. The application would need to store that information itself. You could do this by extending Progress.Data.BindingSource and subscribing to the BindingComplete event*. You could then store the controls that are bound to the current binding source (in a temp-table or array).

Alternatively, you can store the binding source and it's targets as part of your application's infrastructure (in a manager or in a Presenter if you've used the Model-View-Presenter pattern).

Once you have determine that is

there a way to move the control from that binding

source to another, keeping the parameters set by the

programmer for the first binding source.

What parameters do you mean here? Either method above could allow you to store any information you chose to about the binding.

-- peter

  • http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingmanagerbase.onbindingcomplete.aspx has the following remarks:

"

The OnBindingComplete method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

Notes to Inheritors:

When overriding OnBindingComplete in a derived class, be sure to call the base class's OnBindingComplete method so that registered delegates receive the event.

"

Posted by Admin on 10-Nov-2008 15:10

I'm not 100% sure, if there's a way to get that info from the binding source itself. Each Control (inherited from System.Windows.Forms.Control) has a DataBindings collection.

Each object of that collection (a Binding object) has a DataSource property. That holds a reference to the BindingSource.

So one way might be to iterate through each Control in a Contrainer (the Controls collection) and evaluate the DataBindings collection. It must be recursive, because in a Form design there might be other ContainerControls (like panels, etc)....

But may I ask: Why would you want to do that?

You can re-use a binding source by changing the value of the Handle propery. So you could use it for one query or the other, one dataset or the other...

Posted by Freddy Boisseau on 11-Nov-2008 16:34

I have more then one form that need to shared a binding/datasource so that they all point to the same record image. I have figured out how to do this, but in order to make in work the bindings need to be programmed manually. I could just do everything manually, but that removes the ability for the programmers to use the design tools.

So what I have done is create a dummy binding source that is used just for design. The programmer using the visual builder defines and sets all the properties for the databindings. They then need to copy the bindings that are defined from the "InitializeComponent" to another section that resets the binding.

I would like to change the code in the "InitializeComponent". But in order to make that work, I would have to replace the dummy bindingsource with the correct one before the "InitializeComponent" is executed. But "InitializeComponent" is also where the bindingsource is defined. This creates a catch 22.

Any suggestions?

This thread is closed