I have a ComboBox called Number of Candidates and I have 10 other comboBoxes, Upon selecting the number of candidates from the drop down menu that 10 ComboBoxes should be shown or hidden.
For example : I select number of candidates as 3 then ComboBox1 ComboBox2, ComboBox3 should be visible. If I select 2 then only ComboBox1 and ComboBox2 should be visible, rest should be hidden.
I have written below code which works fine for step up like 2 to 3, 3 to 5 like that.. For step down like 4 to 2 it won't work. Could you guys please help me
private void noOfCandidates_SelectedIndexChanged(object sender, EventArgs e)
{
int value = Convert.ToInt16(noOfCandidates.SelectedItem);
if (value == 1)
{
candidateBox1.Visible = true; candidate2lbl.Visible = true;
}
else if (value == 2)
{
candidateBox1.Visible = true; candidate2lbl.Visible = true;
candidateBox2.Visible = true; candidate3lbl.Visible = true;
}
else if (value == 3)
{
candidateBox1.Visible = true; candidate2lbl.Visible = true;
candidateBox2.Visible = true; candidate3lbl.Visible = true;
candidateBox3.Visible = true; candidate4lbl.Visible = true;
}
else if (value == 4)
{
candidateBox1.Visible = true; candidate2lbl.Visible = true;
candidateBox2.Visible = true; candidate3lbl.Visible = true;
candidateBox3.Visible = true; candidate4lbl.Visible = true;
candidateBox4.Visible = true; candidate5lbl.Visible = true;
}
}