private void ButtonEdit_Click(object sender, RoutedEventArgs e) { GetAll_CountryCodes_Record selected_record = dataGrid.SelectedItem as GetAll_CountryCodes_Record; if (selected_record == null) { return; } EditCountryViewModel edit_model = new EditCountryViewModel { Mode = EditCountryViewModel.ModelMode.Edit, CountryCodeID = selected_record.CountryCodeID }; EditCountryWindow window = new EditCountryWindow(edit_model); window.Owner = this; window.ShowDialog(); if (window.DialogResult == false) { return; } // Refresh the country name is the DataGrid. selected_record.Name = edit_model.Name; }
private void ButtonNew_Click(object sender, RoutedEventArgs e) { EditCountryViewModel edit_model = new EditCountryViewModel { Mode = EditCountryViewModel.ModelMode.New }; EditCountryWindow window = new EditCountryWindow(edit_model); window.Owner = this; window.ShowDialog(); if (window.DialogResult == false) { return; } // Add the new country code to the DataGrid. This is just to give visual feedback to // the user. The changes to the recordset will not be send to the database by calling SaveChanges() var grid_record = ViewModel.CountriesRS.NewRecord(); grid_record.CountryCodeID = edit_model.CountryCodeID; grid_record.Name = edit_model.Name; ViewModel.CountriesRS.Append(grid_record); dataGrid.SelectedItem = grid_record; dataGrid.ScrollIntoView(grid_record); }