I have an order entry app that divides the data entry between different tabs. I have a square footage and a 50 cent surcharge based on the square footage with both textboxes on the same tab. The salespeople want the surcharge to calculate as they are typing in the footage.
I have tried both of the following:
1) This approach places the result directly into surcharge textbox
Problem: When you switch tabs, the databinding does not realize that the surcharge textbox has changed and forces the old, stale value back into the surcharge textbox. Therefore, if the surcharge starts out at $50, the footage is changed and the surcharge ends up at $100, it will change back to $50 when you switch tabs. The $100 you place into the textbox never makes it into the DataTable.
2) This approach places the result into the underlying DataTable
Problem: When you update the DataTable in the middle of the edit, it forces the original value of the footage back into the textbox that you are editing. Therefore, if the footage starts at 48 and you delete the 4, the text will be set back to 48 even as you are typing.
I have tried both of the following:
1) This approach places the result directly into surcharge textbox
Code:
private void txtFootage_TextChanged(object sender, System.EventArgs e) {
txtSurcharge.Text = (double.Parse(txtFootage.Text) * 0.50).ToString();
}
2) This approach places the result into the underlying DataTable
Code:
private void txtFootage_TextChanged(object sender, System.EventArgs e) {
tblOrder.Surcharge = double.Parse(txtFootage.Text) * 0.50;
}