M
Michael Wong
Hi there!
I am new to databinding in .Net and I think I am going to get crazy...
What I need to do is this:
1) Create a new form for the user to enter a new Product
2) Save changes (if any) when the user closes the form
But I still couldn't get what I want, even after searching in Google.
Anyone can give me a pointer/hint?
Here is the details:
1) The form FormProduct (in which textboxes are bound) gets loaded:
private void FormProduct_Load(object sender, System.EventArgs e)
{
cmProduct = (CurrencyManager)BindingContext[dsProduct,"Products"];
LoadData();
cmProduct.AddNew();
}
2) Users either enter something or just close the form
3) Before closing the form, save any changes (I am stuck here):
private void FormProduct_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
cmProduct.EndCurrentEdit(); // Saw this in several places already
if(dsProduct.HasChanges())
SaveData();
}
The problem is this:
if I don't call cmProduct.EndCurrentEdit(), then changes will not be
detected.
But if the user hasn't entered anything, they just close the form (like
a cancel), dsProduct.HasChanges() will return true (because we added a
row in the dataset).
Any solution?
I am new to databinding in .Net and I think I am going to get crazy...
What I need to do is this:
1) Create a new form for the user to enter a new Product
2) Save changes (if any) when the user closes the form
But I still couldn't get what I want, even after searching in Google.
Anyone can give me a pointer/hint?
Here is the details:
1) The form FormProduct (in which textboxes are bound) gets loaded:
private void FormProduct_Load(object sender, System.EventArgs e)
{
cmProduct = (CurrencyManager)BindingContext[dsProduct,"Products"];
LoadData();
cmProduct.AddNew();
}
2) Users either enter something or just close the form
3) Before closing the form, save any changes (I am stuck here):
private void FormProduct_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
cmProduct.EndCurrentEdit(); // Saw this in several places already
if(dsProduct.HasChanges())
SaveData();
}
The problem is this:
if I don't call cmProduct.EndCurrentEdit(), then changes will not be
detected.
But if the user hasn't entered anything, they just close the form (like
a cancel), dsProduct.HasChanges() will return true (because we added a
row in the dataset).
Any solution?