Я обычный парень, который учится программировать. Я не люблю, когда код выглядит неряшливо и его можно консолидировать. При этом мне нужно консолидировать некоторый код, но мне не удалось найти информацию о том, как это сделать.
Я пытаюсь включить/отключить несколько текстовых полей на основе выбора поля со списком.
Вот длинный и уродливый код, который я пытаюсь объединить
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
int Combobox_Process_Selected_Index = comboBox2.SelectedIndex;
if (Combobox_Process_Selected_Index == 0)
{
textBox2.Enabled = false;
textBox3.Enabled = false;
textBox4.Enabled = false;
textBox5.Enabled = false;
textBox6.Enabled = false;
textBox7.Enabled = false;
textBox8.Enabled = false;
textBox9.Enabled = false;
textBox10.Enabled = false;
textBox11.Enabled = false;
textBox12.Enabled = false;
textBox13.Enabled = false;
}
if (Combobox_Process_Selected_Index == 1)
{
textBox2.Enabled = true;
textBox3.Enabled = false;
textBox4.Enabled = false;
textBox5.Enabled = false;
textBox6.Enabled = false;
textBox7.Enabled = false;
textBox8.Enabled = false;
textBox9.Enabled = false;
textBox10.Enabled = false;
textBox11.Enabled = false;
textBox12.Enabled = false;
textBox13.Enabled = false;
}
if (Combobox_Process_Selected_Index == 2)
{
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = false;
textBox5.Enabled = false;
textBox6.Enabled = false;
textBox7.Enabled = false;
textBox8.Enabled = false;
textBox9.Enabled = false;
textBox10.Enabled = false;
textBox11.Enabled = false;
textBox12.Enabled = false;
textBox13.Enabled = false;
}
if (Combobox_Process_Selected_Index == 3)
{
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox5.Enabled = false;
textBox6.Enabled = false;
textBox7.Enabled = false;
textBox8.Enabled = false;
textBox9.Enabled = false;
textBox10.Enabled = false;
textBox11.Enabled = false;
textBox12.Enabled = false;
textBox13.Enabled = false;
}
if (Combobox_Process_Selected_Index == 4)
{
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox5.Enabled = true;
textBox6.Enabled = false;
textBox7.Enabled = false;
textBox8.Enabled = false;
textBox9.Enabled = false;
textBox10.Enabled = false;
textBox11.Enabled = false;
textBox12.Enabled = false;
textBox13.Enabled = false;
}
if (Combobox_Process_Selected_Index == 5)
{
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox5.Enabled = true;
textBox6.Enabled = true;
textBox7.Enabled = false;
textBox8.Enabled = false;
textBox9.Enabled = false;
textBox10.Enabled = false;
textBox11.Enabled = false;
textBox12.Enabled = false;
textBox13.Enabled = false;
}
if (Combobox_Process_Selected_Index == 6)
{
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox5.Enabled = true;
textBox6.Enabled = true;
textBox7.Enabled = true;
textBox8.Enabled = false;
textBox9.Enabled = false;
textBox10.Enabled = false;
textBox11.Enabled = false;
textBox12.Enabled = false;
textBox13.Enabled = false;
}
if (Combobox_Process_Selected_Index == 7)
{
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox5.Enabled = true;
textBox6.Enabled = true;
textBox7.Enabled = true;
textBox8.Enabled = true;
textBox9.Enabled = false;
textBox10.Enabled = false;
textBox11.Enabled = false;
textBox12.Enabled = false;
textBox13.Enabled = false;
}
if (Combobox_Process_Selected_Index == 8)
{
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox5.Enabled = true;
textBox6.Enabled = true;
textBox7.Enabled = true;
textBox8.Enabled = true;
textBox9.Enabled = true;
textBox10.Enabled = false;
textBox11.Enabled = false;
textBox12.Enabled = false;
textBox13.Enabled = false;
}
if (Combobox_Process_Selected_Index == 9)
{
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox5.Enabled = true;
textBox6.Enabled = true;
textBox7.Enabled = true;
textBox8.Enabled = true;
textBox9.Enabled = true;
textBox10.Enabled = true;
textBox11.Enabled = false;
textBox12.Enabled = false;
textBox13.Enabled = false;
}
if (Combobox_Process_Selected_Index == 10)
{
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox5.Enabled = true;
textBox6.Enabled = true;
textBox7.Enabled = true;
textBox8.Enabled = true;
textBox9.Enabled = true;
textBox10.Enabled = true;
textBox11.Enabled = true;
textBox12.Enabled = false;
textBox13.Enabled = false;
}
if (Combobox_Process_Selected_Index == 11)
{
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox5.Enabled = true;
textBox6.Enabled = true;
textBox7.Enabled = true;
textBox8.Enabled = true;
textBox9.Enabled = true;
textBox10.Enabled = true;
textBox11.Enabled = true;
textBox12.Enabled = true;
textBox13.Enabled = false;
}
if (Combobox_Process_Selected_Index == 12)
{
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox5.Enabled = true;
textBox6.Enabled = true;
textBox7.Enabled = true;
textBox8.Enabled = true;
textBox9.Enabled = true;
textBox10.Enabled = true;
textBox11.Enabled = true;
textBox12.Enabled = true;
textBox13.Enabled = true;
}
}