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 DataViewForm : Form { public DataViewForm() { InitializeComponent(); } private void bindingNavigatorSaveItem_Click(object sender, EventArgs e) { if( this.Validate() ) { this.customersBindingSource.EndEdit(); this.customersTableAdapter.Update(this.northwindDataSet.Customers); } else { System.Windows.Forms.MessageBox.Show(this, "Validation errors occurred.", "Save", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } } private void DataViewForm_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'northwindDataSet.Customers' table. You can move, or remove it, as needed. this.customersTableAdapter.Fill(this.northwindDataSet.Customers); this.sortButton.Enabled = this.customersBindingSource.SupportsSorting | this.customersBindingSource.SupportsAdvancedSorting; this.searchButton.Enabled = this.customersBindingSource.SupportsSearching; this.filterButton.Enabled = this.customersBindingSource.SupportsFiltering; } private void sortButton_Click(object sender, EventArgs e) { string sortCriteria = this.sortCriteriaTextBox.Text; this.customersBindingSource.Sort = sortCriteria; } private void removeSortButton_Click(object sender, EventArgs e) { this.customersBindingSource.RemoveSort(); } private void searchButton_Click(object sender, EventArgs e) { // Get search criteria string searchColumn = this.searchColumnTextBox.Text; string searchValue = this.searchValueTextBox.Text; // Execute search int index = this.customersBindingSource.Find(searchColumn, searchValue); // Select row this.customersBindingSource.Position = index; } private void filterButton_Click(object sender, EventArgs e) { string filterCriteria = this.filterCriteriaTextBox.Text; this.customersBindingSource.Filter = filterCriteria; } private void removeFilterButton_Click(object sender, EventArgs e) { this.customersBindingSource.RemoveFilter(); } } }