private void dataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { //Get the dataGrid that called the event DataGrid dataGrid = sender as DataGrid; if (e.EditAction == DataGridEditAction.Commit) { var column = e.Column as DataGridBoundColumn; if (column != null) { var newValue = (e.EditingElement as TextBox).Text; //Don't allow empty fields because MyDB does not support that. if (newValue == "") { currentDataGrid.CancelEdit(); return; } DataGridCellInfo selected = dataGrid.SelectedCells[0]; string selectedId = ((Customer)selected.Item).CustomerID; Customer customer = new Customer(selectedId, "", "", ""); if (column.Header.Equals("CompanyName")) { customer.CompanyName = newValue; } if (column.Header.Equals("ContactName")) { customer.ContactName = newValue; } if (column.Header.Equals("Phone")) { customer.Phone = newValue; } CurrentTable.UpdateByID(customer); } } }