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.

the results described above.

i've made following observations:

  1. changing borderstyle of first textbox else @ beginning of form1_load cause display original value , not new value.
  2. none of commented-out lines correct problem if they're uncommented.
  3. moving text assignment after border style change correct this, example simplified version of more complex application uses form class inheritance.
  4. commenting out databindings correct this, not feasible option.
  5. putting new textbox on form , setting first control focus not change observed behaviour.
  6. setting text value of _sampleobjectn.mytext instead of textboxn.text reverses behaviour textbox without border change displays old value , other 2 display new value.
  7. changing datasourceupdatemode datasourceupdatemode.onpropertychanged correct 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

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -