Question Design-time binding on custom control

OpticTygre

New member
Joined
Oct 22, 2008
Messages
4
Programming Experience
5-10
Hi all,

I have a windows form that contains a bindingsource with its datasource set to a bindable object.

I'm creating a user control with a simple label and textbox on it. I have declared a bindable property on the usercontrol using the System.ComponentModel.Bindable(True) attribute flag. This allows me to bind a property of the object on the main form to the property declared in my user control.

What I'd like to do, however, is detect the property name that was bound at design-time, and update the label1.text on my user control based on the property name.

How can I detect that the binding has changed at design-time, and proceed to get the information about the binding and update any internal controls of my user control, so they update in the designer?

Thanks for any advice anyone can provide.

-Jason
 
You can add handler for DataBindings.CollectionChanged event dynamically:
VB.NET:
AddHandler Me.DataBindings.CollectionChanged, AddressOf DataBindings_CollectionChanged
or declare a WithEvents variable pointing to the DataBindings:
VB.NET:
Private WithEvents Bindings As ControlBindingsCollection = Me.DataBindings
For the latter you can select the object/event in code view as with other WithEvents objects. For the former you have to write the handler method manually according to the event signature.
 
You can add handler for DataBindings.CollectionChanged event dynamically:
VB.NET:
AddHandler Me.DataBindings.CollectionChanged, AddressOf DataBindings_CollectionChanged
or declare a WithEvents variable pointing to the DataBindings:
VB.NET:
Private WithEvents Bindings As ControlBindingsCollection = Me.DataBindings
For the latter you can select the object/event in code view as with other WithEvents objects.

That's perfect, John. Exactly what I was looking for, thank you! I thought it might be a little more difficult than that - declaring not-so-well-known attributes from the Component Model or something. This is much simpler. Thanks again.
 
Back
Top