private void buttonEditVar_Click(object sender, EventArgs e) { AddVariable addVariable = new AddVariable(); addVariable.Text = "Edit"; addVariable.nameTextBox.Text = dataGridViewVar.SelectedRows[0].Cells[0].Value.ToString(); addVariable.txtDescription.Text = dataGridViewVar.SelectedRows[0].Cells[1].Value.ToString(); for (int i = 0; i < panelTable.Rows.Count; i++) { addVariable.comboBoxPanel.Items.Add(panelTable.Rows[i].Cells[0].Value.ToString()); } addVariable.comboBoxPanel.SelectedItem = dataGridViewVar.SelectedRows[0].Cells[2].Value.ToString(); if (addVariable.ShowDialog() == DialogResult.OK) { dataGridViewVar.SelectedRows[0].Cells[0].Value = addVariable.nameTextBox.Text; dataGridViewVar.SelectedRows[0].Cells[1].Value = addVariable.txtDescription.Text; dataGridViewVar.SelectedRows[0].Cells[2].Value = addVariable.comboBoxPanel.SelectedItem; } }
private void buttonAddVar_Click(object sender, EventArgs e) { AddVariable addvariable = new AddVariable(); for (int i = 0; i < panelTable.Rows.Count; i++) { addvariable.comboBoxPanel.Items.Add(panelTable.Rows[i].Cells[0].Value.ToString()); } if (addvariable.ShowDialog() == DialogResult.OK) { string variableName = addvariable.nameTextBox.Text; bool nameUnique = true; foreach (DataGridViewRow row in dataGridViewVar.Rows) { if (row.Cells [ 0 ].Value.ToString().Equals(variableName)) { nameUnique = false; break; } } if (nameUnique) { dataGridViewVar.Rows.Add(new Object [ ] { variableName, addvariable.txtDescription.Text, addvariable.comboBoxPanel.SelectedItem }); } else { MessageBox.Show("Name of variable has already exist"); buttonAddVar_Click(sender, e); } } }