private void EditButton_Click(object sender, RoutedEventArgs e) { Room selectedItem = (Room)roomDataGrid.SelectedItem; if (selectedItem != null) { var newRoom = new EditRoomWindow(selectedItem); if (newRoom.ShowDialog() == true) { var update = (from room in MainWindow.db.Rooms where room.ID == selectedItem.ID select room).Single(); update.CategoryID = newRoom.R_CategoryID; update.Price = newRoom.R_Price; update.Status = newRoom.R_Status; update.Picture = newRoom.R_Picture; MainWindow.db.SaveChanges(); roomDataGrid.ItemsSource = MainWindow.db.Rooms.ToList(); } } }
private void roomDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e) { DataGridRow row = ItemsControl.ContainerFromElement((DataGrid)sender, e.OriginalSource as DependencyObject) as DataGridRow; if (row != null) { Room selectedItem = (Room)row.Item; var newRoom = new EditRoomWindow(selectedItem); if (newRoom.ShowDialog() == true) { var update = (from room in MainWindow.db.Rooms where room.ID == selectedItem.ID select room).Single(); update.CategoryID = newRoom.R_CategoryID; update.Price = newRoom.R_Price; update.Status = newRoom.R_Status; update.Picture = newRoom.R_Picture; MainWindow.db.SaveChanges(); roomDataGrid.ItemsSource = MainWindow.db.Rooms.ToList(); } } }