For Example:
private BindingList<Company> companies;
private System.Windows.Forms.BindingSource bindingSource;
private void CompanyForm_Load(object sender, EventArgs e)
{
companies = new BindingList<Company>(PersistenceManager.Instance.RetrieveAll<Company>(SessionAction.BeginAndEnd));
companies.AllowNew = true;
companies.AllowEdit = true;
bindingSource.DataSource = companies;
// Add our bindings
companyIdTextBox.DataBindings.Add("Text", companies, "Id");
companyNameTextBox.DataBindings.Add("Text", companies, "Name");
}
private void toolStripSaveButton_Click(object sender, EventArgs e)
{
// If we have no binding source, then we cannot save
if (null == bindingSource.Current)
{
return;
}
this.Focus();
Company company = bindingSource.Current as Company;
// Save our company
PersistenceManager.Instance.Save<Company>(company);
}
Unless I tab out of the textbox before I click the save button, mybindingSource.Current has not been updated with the text I entered into it.
What am I doing wrong here?
| | zenox Saturday, September 12, 2009 6:03 PM | Try call bindingSource.EndEdit first before save. John Chen
-- See my team blog: http://blogs.msdn.com/vsdata. All my posts are provided "AS IS" with no warranties, and confer no rights.
- Marked As Answer byAland LiMSFT, ModeratorTuesday, September 15, 2009 10:12 AM
-
| | John Chen MS Saturday, September 12, 2009 8:40 PM | Another thing you might want tolook into setting (DataBindings)\(Advanced)\Data Source Update Mode to OnPropertyChanged in the properties for the binding.
By default, this is set to OnValidation which means the data sourceis updatedas part of the Windows Forms Control validation process when a control is exited (or when you call EndEdit to force this to happen earlier).
(For rows being newly added, you will still need an EndEdit at some point to actually get the DataRow into the DataTable. But at least the in-memory data for the DataRow will be updated earlier.) - Marked As Answer byAland LiMSFT, ModeratorTuesday, September 15, 2009 10:12 AM
-
| | BinaryCoder Saturday, September 12, 2009 11:42 PM | Try call bindingSource.EndEdit first before save. John Chen
-- See my team blog: http://blogs.msdn.com/vsdata. All my posts are provided "AS IS" with no warranties, and confer no rights.
- Marked As Answer byAland LiMSFT, ModeratorTuesday, September 15, 2009 10:12 AM
-
| | John Chen MS Saturday, September 12, 2009 8:40 PM | Another thing you might want tolook into setting (DataBindings)\(Advanced)\Data Source Update Mode to OnPropertyChanged in the properties for the binding.
By default, this is set to OnValidation which means the data sourceis updatedas part of the Windows Forms Control validation process when a control is exited (or when you call EndEdit to force this to happen earlier).
(For rows being newly added, you will still need an EndEdit at some point to actually get the DataRow into the DataTable. But at least the in-memory data for the DataRow will be updated earlier.) - Marked As Answer byAland LiMSFT, ModeratorTuesday, September 15, 2009 10:12 AM
-
| | BinaryCoder Saturday, September 12, 2009 11:42 PM |
|