How do you know when all databindings on form are complete?

J

JohnR

I'm running into a 'timing' or 'race' condition on my form. All textbox
controls are bound to a datasource, but certain other controls (like
labels) need to be updated when you move to a different record. In addition
some of the databound controls need to be modified (ie: verified) based on
the values of other databound controls. For example, if one checkbox is
checked, then I need to ensure that another databound control has a certain
value.

The problem is that I can't figure out what event fires when ALL the
databound controls have been updated. Before I start verifying and
updating controls on the form, I want to make sure that all of them have the
latest information. If I use the ControlA.textchanged event how do I know
that ControlB has been updated already? and vice versa.

Does anybody have any suggestions as to how I can determine if all databound
controls have been updated?

Thanks, John
 
J

JohnR

Hi Cor,

Yes, I'm familiar with the parse and format events associated with a
databinding. Trapping the event for each control on the page and then
setting some sort of flag indicating that the control was 'updated' seems
like overkill.

Basically I think I'm looking for something simple... how can I
programmatically test that all controls that are bound to a datasource have
been updated when the 'position' property changes??? If I can test for this
then I can update/verify/modify all the controls on the form knowing that
I'm dealing with current information.

Otherwise I can't be sure that any particular control has been updated
yet. I've got to think that there is something I can look at to see if the
controls are all updated. Clearly, when the update code finishes, and the
mouse gets control and you can click around the form, then you can be sure
all controls have been updated. Is there an event that fires 'just before'
the program starts listening for events (mouse clicks, etc) again? I can't
imagine that this situation has not been addressed previously...

John
 
C

Cor Ligthert [MVP]

JohnR,

In fact should the control which do something be completely be seperated
from your data.

Around your data you have the rules of your busines.

In this case is a dependend from b while b is dependend from c where there
is no sequence.
The moment you know that is when you confirm that the data is well written.
In your case as I understand at a rowchange or at a button command.

That is in my opinion than the place to check if the validity of the created
data is confirm those rules, based on the methods you have in a special
class for this. (but you can start if you have nothing to do it in your code
and than replace that).

Just my idea in this.

Cor
 
L

Larry Lard

JohnR said:
Basically I think I'm looking for something simple... how can I
programmatically test that all controls that are bound to a datasource have
been updated when the 'position' property changes??? If I can test for this
then I can update/verify/modify all the controls on the form knowing that
I'm dealing with current information.

Otherwise I can't be sure that any particular control has been updated
yet. I've got to think that there is something I can look at to see if the
controls are all updated. Clearly, when the update code finishes, and the
mouse gets control and you can click around the form, then you can be sure
all controls have been updated. Is there an event that fires 'just before'
the program starts listening for events (mouse clicks, etc) again? I can't
imagine that this situation has not been addressed previously...

I haven't been able to find any better solution than a form-level
variable dataBinding As Boolean, this kind of code around the binding
operations:

dataBinding = True
Me.MyTableAdapter.FillByID(MyID)
dataBinding = False

and this kind of code in the 'propagation' events:

If Not dataBinding Then
'whatever
End If

Yucky I know, but I didn't get any better suggestions here. Apparently
the BindingSource (or one of those dozens of behind-the-scenes objects
data binding seems to use :)) has a bindingInProgress property, but
it's Private.
 
J

JohnR

In a relentless search for the answer, I stumbled upon an event of the
BindingManagerBase called 'PositionChanged'. From what I can tell from my
testing, it gets fired after the position changes and all controls have been
updated. (If anybody can demonstrate that this is not the case, I'd be
really interested in hearing about it).

In order to set this up you need to get a reference to the
bindingmanagerbase and then hook into the event handler, like this:

Dim MyBMB as bindingmanagerbase =
bindingcontext(ds.tables("yourtable").defaultview)
AddHandler MyBMB.PositionChanged, AddressOf MyBmbPositionChangedSub

After that, the routine 'MyBmbPositionChangedSub' gets called after each
position change.

John
 
J

Jim Hughes

Using 2005, there is a new component called BindingSource that has a
BindingCompleted event.

You bind all of your controls to the BindingSource and set the
BindingSource.DataSource to the actual data object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top