I have invoice form bound to a bindingsource and bindingnavigator. In the form I have unit price, quantity and total textboxes. The total textbox text property is set to total.text = quantity.text * unitprice.text in the textChanged event of both quantity and unitprice text boxes. The result is displayed in the total textbox. But when i hit save button on the bindingnavigator it is set to null and not saved to database.

The code on save button is
bindingsource.endEdit()
bindingsource.update()
When I used msgbox to see the value of total textbox before bindingsource.endEdit() it is the correct value. but after the code bindingsource.endEdit() it is null. I checked the databinding property and it is correct. What is the problem.

Update the field in your data source instead of the .Text value, or update both. Also in your save methods have it call something like buttonSave.Focus() . I believe until a control loses focus (by default) it does not perform validation and update the underlying values in the databound source.

You should not be storing the total in the database it is a derived value and should be calculated on the fly as you need it.

Storing derived values increases the complexity of your application and provides for data inconsistencies to arise. For example, if they don't balance how do you know which is correct.

show me how to update the field in my datasource plz?

i didn't solve this problem. but i deleted the total field from my databse because it is a calculated value. I added a column to my dataset and make its value an expression.

take template field and write on its TextChanged event ....

TextBox tb1 = ((TextBox)(sender));

GridViewRow gv1 = ((GridViewRow)(tb1.NamingContainer));

int rownumber = gv1.RowIndex;

thank you

This question has already been answered. Start a new discussion instead.