Two Way Databinding

himanshubari

Newcomer
Joined
Mar 14, 2005
Messages
9
I have windows form control bound to a business object. Upon initialization it displays the data from the business object in the text box as its bound. But when I update the vale in the text box the respective data member of my business object doesnt get updated.

Any suggestions please?

Thanks
 
The usual reason for that to happen is that your textbox is still in edit mode when the update is donne...

The following line should solve your problem:

Code:
Me.BindingContext(DataSourceObject).EndCurrentEdit()

Alex :p
 
himanshubari said:
Thaks a lot for your help,

But I wanted to know where should I place this line. and what is teh dataSource object?

Put it just before you call the update method.
The DataSource is the main object where the data comes from... (your business object)
 
oops!
I think I am lacking some basoc concepts here. SO I call the endCurrentEdit() method as advised by you.
But, I dont have any update method, So here is what my understanding is.. I bind a control to a property in my business object
Label1.databindings.Add("Text",myPropertyBean,"Name")

SO the value returned by the Name property would appear in the text of the Label1.
Now some other UI component changes this text of Label1.....and I expected that automatically the setter for Name property would be called and the appropriate member variable in my 'myPropertyBean' would be updated

but I thought This would happen AUTOMATICALLY as its databound.

Do i have to manually call this setter method instead as a part of the update method you were talking about??

Sorry for being confusing if I am...

Thanks again
!!
 
Sometimes databinding doesn't work quite the way we expected it to.
Mostly because, sometimes, the UI objects don't end up their edit mode.

So... if you need to change the value in other way that directly typing on the textbox do it directly on the data source object... as databound it will show on the textbox.

Otherwise, try to EndCurrentEdit when loosing focus or something...

Note:
Keep in mind that, i.e. on a databound textbox, the data is only bound when the edit process is finished, not every time you type something on... If the control doesn't end the edit properlly, you will never have your data sync donne.
 
Back
Top