Update list via text box

Oct 25, 2014
Programming Experience
i have this school registration software.


the problem is that i want to update the class automatically with reference to age for example

if age is 2 class is begginer
if age is 3 class is montessori
if age is 4 class is 1
if age is 5 class is 2
if age is 6 class is 3
if age is 7 class is 4 and so on.

i want to use for loop
            //AUTO CLASS UPDATE
            if (agee.Text.ToString().CompareTo("12") == 0 )


but if any solution is there please explain.
You certainly wouldn't use a loop. Loops are for doing the same thing multiple times. You aren't doing anything multiple times so no loop. If there's a direct relationship between the age and the index of the item ListBox then you only need one line that sets the SelectedIndex based on the age. If that's not the case then you could use a `switch` statement.
okay using the switch statement but what would be the code to get the first item highlighted or second and so on ?

I already told you that in my previous post.

EDIT: Actually, I can see how you would not see that I did. You would still set the SelectedIndex or perhaps the SelectedItem. It would simply take more than one line of code to do the whole thing.
Top Bottom