private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { try { String x = dataGridView1.CurrentRow.Cells[0].Value.ToString(); String y = dataGridView1.CurrentRow.Cells[1].Value.ToString(); if (this.x == 0) { op.SetValues(x, y); this.Close(); } else if (this.x == 1) { op1.setDoctor(x, y); this.Close(); } else { op2.SetDoctor(x, y); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }