Binding.Format not alway being called

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

I have a DataBind() method which binds my controls to my business object.
There are times we changes the object without closing the screen and call
DataBind() again. DataBind() calls DataBindings.Clear() and each control
which I bind to before I reset the bindings.

The problem is the first time the binding is done Format gets called but it
doesn't get called after another call to DataBind().

I'm guessing it's because the values are the same but since Format is not
called the values now display their actual value instead of the formatted
value I need.

My binding looks like this for one of the controls:
Binding binding = control.DataBindings.Add("Text", myobject, "myProperty",
true, DataSourceUpdateMode.OnValidation, null);
binding.Format += new ConvertEventHandler(Property_Format);

I have also tried DataSourceUpdateMode.OnPropertyChanged


Any suggestions?
Joe
 
Hi,

Joe said:
I have a DataBind() method which binds my controls to my business object.
There are times we changes the object without closing the screen and call
DataBind() again. DataBind() calls DataBindings.Clear() and each control
which I bind to before I reset the bindings.

The problem is the first time the binding is done Format gets called but
it doesn't get called after another call to DataBind().

I'm guessing it's because the values are the same but since Format is not
called the values now display their actual value instead of the formatted
value I need.

I think, it's because the first time the form isn't (fully) loaded, the
actual data push from source to control happens some time after adding the
Binding so you still get the event. On repeat the form is loaded and adding
a databinding immediately causes a data push so the Format event is fired
but before you've added the eventhandler.

Add the eventhandler before you add the Binding, eg. :

Binding binding = new Binding("Text", myobject, "myProperty", true,
DataSourceUpdateMode.OnValidation, null);
binding.Format += new ConvertEventHandler(Property_Format);
control.DataBindings.Add( binding );


HTH,
greetings
 
That work. Thanks!

Bart Mermuys said:
Hi,



I think, it's because the first time the form isn't (fully) loaded, the
actual data push from source to control happens some time after adding the
Binding so you still get the event. On repeat the form is loaded and
adding a databinding immediately causes a data push so the Format event is
fired but before you've added the eventhandler.

Add the eventhandler before you add the Binding, eg. :

Binding binding = new Binding("Text", myobject, "myProperty", true,
DataSourceUpdateMode.OnValidation, null);
binding.Format += new ConvertEventHandler(Property_Format);
control.DataBindings.Add( binding );


HTH,
greetings
 
Back
Top