コード例 #1
0
        private void EditButton_Click(object sender, RoutedEventArgs e)
        {
            Category selectedItem = (Category)categoryDataGrid.SelectedItem;

            if (selectedItem != null)
            {
                var newCategory = new EditCategoryWindow(selectedItem);

                if (newCategory.ShowDialog() == true)
                {
                    var updatecategory = (from category in MainWindow.db.Categories where category.ID == selectedItem.ID select category).Single();
                    updatecategory.Name = newCategory.CT_Name;
                    MainWindow.db.SaveChanges();

                    categoryDataGrid.ItemsSource = MainWindow.db.Categories.ToList();
                }
            }
        }
コード例 #2
0
        private void categoryDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGridRow row = ItemsControl.ContainerFromElement((DataGrid)sender, e.OriginalSource as DependencyObject) as DataGridRow;

            if (row != null)
            {
                Category selectedItem = (Category)row.Item;

                var newCategory = new EditCategoryWindow(selectedItem);

                if (newCategory.ShowDialog() == true)
                {
                    var update = (from category in MainWindow.db.Categories where category.ID == selectedItem.ID select category).Single();
                    update.Name = newCategory.CT_Name;
                    MainWindow.db.SaveChanges();

                    categoryDataGrid.ItemsSource = MainWindow.db.Categories.ToList();
                }
            }
        }