468,720 Members | 1,747 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,720 developers. It's quick & easy.

How to Use the Same BindingSource Across Multiple UserControls

Hello:

I'm working on improving some of our Windows Forms.

I have created two user controls that I want to bind to the same
BindingSource.

I have an overview control that is used just to identify a customer.
Then there is a details view that shows all their specifics. I wanted
to keep navigation outside of my view. There is also a
BindingNavigator that I want to hook up to the same BindingSource.
When I navigate, I want the two user controls to keep in-sync.

The problem is that I have a BindingSource in each control and I bind
all the child controls to it. So, when I try to change the
BindingSource, it appears as though nothing happens. This is because
the child controls are hard-set to point at the original
BindingSource.

Is there a way to change which BindingSource the child controls are
looking at?

Tell me if I'm being unclear.

Thanks,
Travis
Sep 19 '08 #1
2 4293
I found a working solution to this problem. I created a class called
IndirectBindingSource. It inherits from and implements all the classes
and interfaces of BindingSource. I implement all of the methods by
redirecting them to the methods inside a BindingSource that I pass via
a property.

The designer just thinks I have another BindingSource. In my user
controls, I still have a BindingSource that points to the data. I set
my IndirectBindingSource's BindingSource to that BindingSource. The
BindingSource picks up all the type properties. My
IndirectBindingSource picks up all of those properties too. I just
bind my user controls to the IndirectBindingSource.

My user controls provide a property called BindingSource that will get
and set the BindingSource inside the IndirectBindingSource. Since
these properties are visible to the Designer, I can set all my
BindingSources at design time.

At run time, I just set the DataSource of the BindingSource in my main
form. Since every control uses the same BindingSource, directly or
indirectly, everything works out smoothly.

It is pretty cool, if not a little hackish. The code is pretty simple
too. Outside of the user controls, no one has any clue I am being
sneaky.
Sep 19 '08 #2
I have to say this is a most confusing description of a problem.

If you want the binding source to follow everything then ALL controls
should bind to it. When you want to split you then have to create a
second binding source. For example, I have two players from one team on
the field at any one time, I have a tab with two binding sources one for
each player and they work independently. If I use one binding source for
all then changing details on one player will change the second to that
player automatically.

I had problems changing position on a binding source this was related to
null datetime elements, the datetime controls reject the update and the
binding source moves you back.
Sep 20 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jim Tilson | last post: by
13 posts views Thread by Samir Chouaieb | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Oskars | last post: by
9 posts views Thread by bryonone | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.