private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0) { //del if (MessageBox.Show("Вы действительно хотите удалить запись?", "Внимание", MessageBoxButtons.YesNo) == DialogResult.Yes) { using (SqlConnection sqlConnection = new SqlConnection(url)) { sqlConnection.Open(); var rowIndex = e.RowIndex; var cell = dataGridView1.Rows[rowIndex].Cells[2].Value; var com1 = new SqlCommand("DELETE FROM Table_User WHERE [Id_Role] = '" + cell + "' ", sqlConnection); SqlDataReader sqldr = com1.ExecuteReader(); dataGridView1.Rows.RemoveAt(rowIndex); } MessageBox.Show("Данные успешно удалены!", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } } if (e.ColumnIndex == 1) { //edit UsersInfo usersInfo = new UsersInfo(userList[e.RowIndex], false, this); usersInfo.Show(); } }
private void button1Add_Click(object sender, EventArgs e) { UsersInfo usersInfo = new UsersInfo(null, true, this); usersInfo.Show(); }