Beispiel #1
0
        private async void dataGridViewMain_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }

            try
            {
                richTextBoxLog.Text += $"dataGridViewMain_CellValueChanged: row {e.RowIndex}, column {e.ColumnIndex}, value {dataGridViewMain.Rows[e.RowIndex].Cells[e.ColumnIndex].Value} \n";
                var boundedItem = ((DataGridView)sender).CurrentRow.DataBoundItem;

                if (boundedItem is CropGroup)
                {
                    richTextBoxLog.Text += $"dataGridViewMain_CellValueChanged: {((CropGroup)boundedItem).CropGroupId}, {((CropGroup)boundedItem).CropGroupName}, {((CropGroup)boundedItem).Crops.Count} \n";
                    if (((CropGroup)boundedItem).CropGroupId == 0)
                    {
                        boundedItem = await _cropGroupRepository.AddCropGroupAsync((CropGroup)boundedItem);

                        ((DataGridView)sender).Invalidate();
                    }
                    else
                    {
                        await _cropGroupRepository.UpdateCropGroupAsync((CropGroup)boundedItem);
                    }
                }

                //_context.Update(boundedItem);
                //_context.SaveChanges();
            }
            catch (Exception exc)
            {
                richTextBoxLog.Text += $"dataGridViewMain_CellValueChanged failed: {exc.Message}";
            }
        }