Databinding and User Controls

Posted by Admin on 17-Sep-2008 19:38

Forgive me if I'm being dense...

I've got a form containing a binding source, an UltraTab with controls that attach to the binding source columns. The form can contain multiple tabs with all controls on all tabs using the same binding source.

I'd like to create user controls for each tab that contain all the controls for the tab. Essentially, instead of dropping 10 controls on a tab, I drop one user control which contains those 10 controls.

What is the proper / easiest way to bind the controls within the user controls to the form's binding source? I don't (think I) want binding sources within the user controls. And there could be any reasonable number of controls per tab.

Thanks!

JL

All Replies

Posted by Admin on 24-Sep-2008 12:09

Hay Jim,

I haven't tried this and it's off the top of my head and I'm not too sure some of this is possible ... :); I would create an interface that defines a method that can take a binding source as a parameter. Then use that interface on your users controls. Inside this method loop through all of the controls that are bindable and set the binding source.

Then at runtime loop through the tabs, get the user control on that tab casting it to the interface and call the method that sets the binding source.

Regards,

M

Posted by Admin on 24-Sep-2008 12:31

Thanks Mike.

I ended up doing something similar, but without the interface.

Basically I pass the binding source of the form to a method in the user control that loops though a list of controls and binds them. Seems to work pretty well (so far!).

JL

Posted by Admin on 25-Sep-2008 03:48

Good to know I wasn't too far off the mark.

The only reason I suggested the interface was so that you can check to see if the control on the tab supports the setting of a binding source. This way if you put other controls on the tab you have an easy way of ignoring them.

Regards,

M

This thread is closed