Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 369
  • Last Modified:

Strange Behavior : TextBox.Text got cleared after calling Me.BindingContext(DataSet1.Tables("DETAIL")).AddNew()

i am using VB.Net 2003

i found a strange behavior:
after calling Me.BindingContext(DataSet1.Tables("DETAIL")).AddNew(),
TWO of my TextBox.Text values got cleared automatically.
this weird behavior occured when DataSet1.Tables("DETAIL") already has a RECORD or more,
thus if the table is EMPTY, this behavior did not occured, all my TextBoxes.Text values did not get cleared

this is my code:
Note: all TextBoxes except txtID are in GroupBox1

Dim BMB As BindingManagerBase = Me.BindingContext(DataSet1.Tables("DETAIL"))

BMB.EndCurrentEdit()
BMB.AddNew() '--> after this call, two of my TextBox.Text values got cleared
BMB.Current("SRExportID") = Trim(txtID.Text)
BMB.Current("Article") = Trim(txtArticle.Text) '--> this TextBox.Text got cleared
BMB.Current("Material1") = Trim(txtMaterial1.Text)
BMB.Current("Material2") = Trim(txtMaterial2.Text)
BMB.Current("Material3") = Trim(txtMaterial3.Text)
BMB.Current("Material4") = Trim(txtMaterial4.Text)
BMB.Current("Last1") = Trim(txtLast1.Text) '--> this TextBox.Text got cleared
BMB.Current("Quantity") = Trim(txtQuantity.Text)
BMB.Current("Remark") = Trim(txtRemark.Text)
BMB.EndCurrentEdit()


anyone ever had similar experience?
could anyone tell me why did it happen?
why it only occured when DataSet1.Tables("DETAIL") already has a record or more?
why only TWO TextBoxes are affected by this strange behavior?

thanks
0
yukimura
Asked:
yukimura
  • 3
  • 3
1 Solution
 
Wim_BlCommented:
Hi,

are they bound to your BMB in another way then the others ? The AddNew might result in clearing the boxes to put the data for the new records in them. Just a thought though...

greetings
0
 
BClementsCommented:
What is the first BMB.EndCurrentEdit() before BMB.Add()? - just curious, I don't know if that affects anything or not.

I second Wim_Bl, how are the unaffected controls bound?

When I use BMB.AddNew() all the controls bound to that dataset are cleared and waiting for new input.  
BMB.EndCurrentEdit()  is called when the user clicks on the Update button after the new data is input.
0
 
yukimuraAuthor Commented:
Wim_Bl,
the TextBoxes are not bound to anything
the Dataset table is set as the datasource for my datagrid, but this is not supposed to affect the TextBoxes

BClements,
as far as i know, BMB.EndCurrentEdit() is used to end any current edit on the dataset table
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BClementsCommented:
Are the two textboxes that are changing bound to the dataset?  If so, you can try unbinding them so they are like the other text boxes and see if that works.
0
 
yukimuraAuthor Commented:
BClements,
No all the textboxes (the ones that got cleared and the ones that are fine) are not bind to anything

i did set the DataSet Table as the DataSource for a DataGrid and as DataView... but it should not affect the textboxes... this is weird

because of this glitch, i have to set the value of my cleared textboxes (only 2 out of 8) to local variables before the call to BMB.AddNew()
then set them back to those textboxes after i add a record.

oh well did anyone ever got this kind of problem?
0
 
BClementsCommented:
Maybe the problem lies in the BindingContextManager.  If your controls are not bound, then I don't see why you are using it.  

Maybe you will get the result you want by just using the table and row methods instead of the BindingContextManager.
0
 
yukimuraAuthor Commented:
BClements,
maybe you are right

i use the BindingContextManager to navigate the records in Dataset Table
but the textboxes are not bound to BindingContextManager, thus it should not cleared the TextBoxes... even if it does, it should cleared all the TextBoxes not just 2 out of 8

but anyway i just save the values of those 2 textboxes to a local variables then set the values back to them after the call to AddNew

thanks
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now