Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a form with one label and few textboxes. These controls have data bindings with DataTable "myTable".
After "Add New" button click, the all controls with data are empty. I need to preserve the value of the label. Is that possible ?

Here are more details:

SelectCommand:
SELECT t1.FieldX, t2.FieldA, t2.FieldB
FROM table1 t1
JOIN table2 t2 on t2.FieldY = t1.FieldX


Data binding:
LABEL.DataBindings.Add("Text", myTable, "FieldX")
TEXTBOX1.DataBindings.Add("Text", myTable, "FieldA")
TEXTBOX2.DataBindings.Add("Text", myTable, "FieldB")



Part of code at "Add New" button click event :
// insert data to database table table2 
...
BindingContext(myTable).EndCurrentEdit()
BindingContext(myTable).AddNew()
// after that all values are empty
// need to preserve label value
...
Posted
Updated 21-Dec-10 12:48pm
v2
Comments
aidin Tajadod 21-Dec-10 19:18pm    
hi,
Maybe you can get the value of your text box and reinitial them after AddNew() function!
(just a suggestion)

1 solution

If you expect all the controls to be bound to the save record, then no, you cannot preserve the contents of the label.

But, if the label was being bound by its own BindingContext, then you can have multiple sets of bindings instead of the forms default where all the controls are bound to the same record.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900