vb.net - Setting a databound TextBox control's BorderStyle overrides the new Text value -
i've found , able reproduce peculiar behaviour in windows forms, in updating text in databound textbox , changing borderstyle override new text value.
to reproduce: create new form, add 3 textbox controls, , use following code:
public class form1 private class sampleobject public property mytext string = string.empty end class private _sampleobject1 new sampleobject {.mytext = "old text 1"} private _sampleobject2 new sampleobject {.mytext = "old text 2"} private _sampleobject3 new sampleobject {.mytext = "old text 3"} private sub form1_load(sender object, e eventargs) handles me.load textbox1.databindings.add(new binding("text", _sampleobject1, "mytext", true, datasourceupdatemode.onvalidation, string.empty)) textbox2.databindings.add(new binding("text", _sampleobject2, "mytext", true, datasourceupdatemode.onvalidation, string.empty)) textbox3.databindings.add(new binding("text", _sampleobject3, "mytext", true, datasourceupdatemode.onvalidation, string.empty)) textbox1.text = "new text 1" textbox2.text = "new text 2" textbox3.text = "new text 3" 'application.doevents() '<- won't fix this. 'textbox2.invalidate() '<- won't fix this. 'textbox2.update() '<- won't fix this. 'textbox2.refresh() '<- won't fix this. textbox1.borderstyle = borderstyle.fixed3d textbox2.borderstyle = borderstyle.fixedsingle textbox3.borderstyle = borderstyle.none end sub end class running application give form 3 textboxes. first 1 display new text value, border style has not changed. other 2 textboxes display old values.

i've made following observations:
- changing borderstyle of first textbox else @ beginning of form1_load cause display original value , not new value.
- none of commented-out lines correct problem if they're uncommented.
- moving text assignment after border style change correct this, example simplified version of more complex application uses form class inheritance.
- commenting out databindings correct this, not feasible option.
- putting new textbox on form , setting first control focus not change observed behaviour.
- setting text value of
_sampleobjectn.mytextinstead oftextboxn.textreverses behaviour textbox without border change displays old value , other 2 display new value. - changing datasourceupdatemode
datasourceupdatemode.onpropertychangedcorrect this, change behaviour of binding.
the obvious fixes change text assignment it's assigned after borderstyle changed or change datasourceupdatemode, question is: why happening in first place?
update: @ request of co-worker, had added button form, , changed click event set borderstyles of controls, commenting out border style code in form_load. when application runs, see new values in textboxes, expected, when click button, borders change on textboxes 2 , 3, , text value reverts old value!
Comments
Post a Comment