jeudi 12 mars 2015

How should I change the visibility of a TextBox when a ComboBox value changes?

I'm new to programming and I'm trying to change the value of a textbox depending of a selected value on a combo box, since the values are numerical 1 to 20, and depending on the selection it will be the number of text boxes visible. I'm using the event selected index changed.


Here is my code:



private void cbxPIN_SelectedIndexChanged(object sender, EventArgs e)
{
int pines = Convert.ToInt32(cbxPIN.SelectedItem.ToString());
if (pines == 1)
{
textbox1.visible = true;
}
else if (pines == 2)
{
textbox1.visible = true;
textbox2.visible = true;
}
...

else if (pines == n)
{
textbox1.visible = true;
textbox2.visible = true;
...
textboxn.visible = true;
}
}


since there are like 25 different numeric values on the combo box is there an easier way of doing this? asides from comparing each different value?


Something like a loop.


Aucun commentaire:

Enregistrer un commentaire