Home All Groups Group Topic Archive Search About

Binding.Format not alway being called

Author
2 Nov 2006 4:28 PM
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

Author
2 Nov 2006 5:29 PM
Bart Mermuys
Hi,

"Joe" <jbassking@noemail.noemail> wrote in message
news:uKYDExp$GHA.1220@TK2MSFTNGP04.phx.gbl...
>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

Show quote
>
> 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
>
Author
2 Nov 2006 6:35 PM
Joe
That work. Thanks!

Show quote
"Bart Mermuys" <bmermuys.nospam@hotmail.com> wrote in message
news:2Wp2h.162655$Li.2598965@phobos.telenet-ops.be...
> Hi,
>
> "Joe" <jbassking@noemail.noemail> wrote in message
> news:uKYDExp$GHA.1220@TK2MSFTNGP04.phx.gbl...
>>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
>
>>
>> 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
>>
>
>

AddThis Social Bookmark Button