private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { sqlConnection = new SqlConnection(_connectionString); if (e.ColumnIndex == 6) { EmpID = Convert.ToString(dataGridViewEmployee.Rows[e.RowIndex].Cells["Id"].Value); this.Hide(); EmployeeInsert employeeInsertFormCollection = Application.OpenForms["EmployeeInsert"] != null ? (EmployeeInsert)Application.OpenForms["EmployeeInsert"] : null; if (employeeInsertFormCollection != null) { employeeInsertFormCollection.Close(); employeeInsertFormCollection.Dispose(); } EmployeeInsert employeeInsert = new EmployeeInsert(); employeeInsert.Show(); } if (e.ColumnIndex == 7) { EmpID = Convert.ToString(dataGridViewEmployee.Rows[e.RowIndex].Cells["Id"].Value); SqlDataAdapter da = new SqlDataAdapter("delete from employee where Id = '" + EmpID + "'", sqlConnection); DataSet ds = new DataSet(); da.Fill(ds); displayDataGridView(); dataGridViewEmployee.Refresh(); } }
private void ButtonReturn_Click(object sender, EventArgs e) { //User has clicked the 'Return' button in the screen isReturn = true; this.Hide(); EmployeeInsert employeeInsertFormCollection = Application.OpenForms["EmployeeInsert"] != null ? (EmployeeInsert)Application.OpenForms["EmployeeInsert"] : null; if (employeeInsertFormCollection != null) { employeeInsertFormCollection.Show(); } else { EmployeeInsert employeeInsert = new EmployeeInsert(); employeeInsert.Show(); } }
private void Employee_Load(object sender, EventArgs e) { EmployeeInsert employeeInsertFormCollection = Application.OpenForms["EmployeeInsert"] != null ? (EmployeeInsert)Application.OpenForms["EmployeeInsert"] : null; if (employeeInsertFormCollection != null) { employeeInsertFormCollection.Hide(); } displayDataGridView(); DataGridViewLinkColumn Editlink = new DataGridViewLinkColumn(); Editlink.UseColumnTextForLinkValue = true; Editlink.HeaderText = "Edit"; Editlink.DataPropertyName = "lnkColumn"; Editlink.LinkBehavior = LinkBehavior.HoverUnderline; Editlink.Text = "Edit"; Editlink.Width = 60; Editlink.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGridViewEmployee.Columns.Add(Editlink); DataGridViewLinkColumn Deletelink = new DataGridViewLinkColumn(); Deletelink.UseColumnTextForLinkValue = true; Deletelink.HeaderText = "Delete"; Deletelink.DataPropertyName = "lnkColumn"; Deletelink.LinkBehavior = LinkBehavior.HoverUnderline; Deletelink.Text = "Delete"; Deletelink.Width = 60; Editlink.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGridViewEmployee.Columns.Add(Deletelink); this.setDataGridViewProperties(); }