Example #1
0
        private void companyGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                //Edit event;
                if (companyGridView.Columns[e.ColumnIndex].Index == 3)
                {
                    int rowIndex = companyGridView.Rows[e.RowIndex].Index;
                    companyNameTextBox.Text = companyGridView.Rows[rowIndex].Cells[2].Value.ToString();

                    companyId   = Convert.ToInt32(companyGridView.Rows[rowIndex].Cells[1].Value);
                    companyName = companyGridView.Rows[rowIndex].Cells[2].Value.ToString();

                    saveCompanyButton.BackColor = Color.Chocolate;
                    saveCompanyButton.Text      = "Update";
                }
                //Delete Event;
                if (companyGridView.Columns[e.ColumnIndex].Index == 4)
                {
                    companyNameTextBox.Clear();
                    saveCompanyButton.BackColor = Color.ForestGreen;
                    saveCompanyButton.Text      = "Save";

                    int rowIndex  = companyGridView.Rows[e.RowIndex].Index;
                    int companyId = Convert.ToInt32(companyGridView.Rows[rowIndex].Cells[1].Value);

                    if (MessageBox.Show("Are you sure want to delete?", "Confirm", MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        _companyManager.DeleteData(companyId);
                        companyBindingSource.DataSource = _companyManager.GetAllCompany();
                        _model.AddAutoIncrementColumn(companyGridView);
                    }
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }