using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace AppliedDataBindingSample { public partial class EmployeesListForm : Form { public EmployeesListForm() { InitializeComponent(); } private void bindingNavigatorSaveItem_Click(object sender, EventArgs e) { if( this.Validate() ) { this.employeesBindingSource.EndEdit(); this.employeesTableAdapter.Update(this.northwindDataSet.Employees); } else { System.Windows.Forms.MessageBox.Show(this, "Validation errors occurred.", "Save", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } } private void ViewEditForm_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'northwindDataSet.Employees' table. You can move, or remove it, as needed. this.employeesTableAdapter.Fill(this.northwindDataSet.Employees); } private void addToolStripButton_Click(object sender, EventArgs e) { this.EditEmployee(this.employeesBindingSource.AddNew()); } private void updateToolStripButton_Click(object sender, EventArgs e) { DataRowView bob = ((DataRowView)this.employeesBindingSource.Current); this.EditEmployee((DataRowView)this.employeesBindingSource.Current); } private void EditEmployee(object item) { // Pass to child employee details form EmployeeItemForm dlg = new EmployeeItemForm(item); if( dlg.ShowDialog() == DialogResult.OK ) { // Reset to reflect changes automatically this.employeesBindingSource.ResetCurrentItem(); } } private void deleteToolStripButton_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show( "Delete current row?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if( result == DialogResult.Yes ) { this.employeesBindingSource.RemoveCurrent(); } } } }