Binding to Autofilled Textbox

Binding to Autofilled Textbox

Old forum URL: forums.lhotka.net/forums/t/5273.aspx


MadGerbil posted on Wednesday, August 20, 2008

I've a simple business object binding to several textboxes.  Most of the values in these textboxes are changed by manually entering values; however, I've a couple of textbox values that are filled in by clicking a button that opens a colordialog.  The result of the colordialog (color) is programatically fed into the textbox.

The value in the textbox changes when this occurs, but the actual value of the property in the underlying object isn't changed.

Fix?

tetranz replied on Wednesday, August 20, 2008

MadGerbil:

I've a simple business object binding to several textboxes.  Most of the values in these textboxes are changed by manually entering values; however, I've a couple of textbox values that are filled in by clicking a button that opens a colordialog.  The result of the colordialog (color) is programatically fed into the textbox.

The value in the textbox changes when this occurs, but the actual value of the property in the underlying object isn't changed.

Fix?


The property value is not changing because nothing is triggering the databinding to send the new value into the object. The binding for the textbox is probably set to happen OnValidation. A quick way to fix this is probably to change the databinding mode to OnPropertyChanged. You can do this in "Advanced" for databinding of the textbox.

I think it would be better for your color dialog to change the value of the object property rather than the textbox. The databinding will then update the textbox. That's how I do this kind of thing. In general, I think if a control is bound to an object, you're best not to change that control any other way. Let it pull the data back from the object.

Copyright (c) Marimer LLC