I have 3 or more ComboBoxes having the same functionality. what I'm thinking is creating a Method and just call it
Here is sample code
Question: Is there any way to Combine this 5 ComboBox into 1 since they have the same functionality and simplify this Method if for example i'm having multiple ComboBoxes
public double comboBoxTry()
{ double x;
if (comboBox1.SelectedItem.ToString() == "First")
{ x = 3.5; }
else if (comboBox1.SelectedItem.ToString() == "Second")
{ x = 4; }
//Second ComboBox and so on
if (comboBox2.SelectedItem.ToString() == "First")
{ x = 3.5; }
else if (comboBox2.SelectedItem.ToString() == "Second")
{ x = 4; }
if (comboBox2.SelectedItem.ToString() == "First")
{ x = 3.5; }
else if (comboBox2.SelectedItem.ToString() == "Second")
{ x = 4; }
if (comboBox3.SelectedItem.ToString() == "First")
{ x = 3.5; }
else if (comboBox3.SelectedItem.ToString() == "Second")
{ x = 4; }
if (comboBox4.SelectedItem.ToString() == "First")
{ x = 3.5; }
else if (comboBox4.SelectedItem.ToString() == "Second")
{ x = 4; }
if (comboBox5.SelectedItem.ToString() == "First")
{ x = 3.5; }
else if (comboBox5.SelectedItem.ToString() == "Second")
{ x = 4; }
// I want to Combine this 5 ComboBox into 1 since they have the same functionality
return x;
}
private void btnCompute_Click(object sender, EventArgs e)
{ txtResult.Text = (x * double.Parse(txtAmount.Text)).ToString(); }
Aucun commentaire:
Enregistrer un commentaire