I have a combo box with 5 pre-defined items. When I execute my code, no matter which item I select from the drop-down, the code always executes the first selection.
cbxLength contains the values 10, 15, 20, 25, 30 which represents the # of years, and I multiple their selection by 12 to calculate the number of months. Why is the code always selection (0) as the index
Thanks for any help you can provide.
If cbxLength.Items(0) ThenNumberPayment = 10 * 12
ElseIf cbxLength.Items(1) ThenNumberPayment = 15 * 12
ElseIf cbxLength.Items(2) ThenNumberPayment = 20 * 12
ElseIf cbxLength.Items(3) ThenNumberPayment = 25 * 12
ElseIf cbxLength.Items(4) ThenNumberPayment = 30 * 12
End IftxtNumberPmt.Text = NumberPayment.ToString
MessageBox.Show(
"Number Payments = " + txtNumberPmt.Text)
Selecting from a Combo Box
craigw33333
Here is a link to work with combobox in VB.NET
http://www.startvbdotnet.com/controls/combo.aspx
Regards
Kuldeep Deokule
Luc Morin
To see what item is selected you should use the SelectedItem property.
NumberPayment = cbxLength.SelectedItem * 12
You should be sure that it actually is something selected by only accessing the SelectedItem property inside a block that has checked that it is not nothing.
If Not cbxLength.SelectedItem Is Nothing Then
NumberPayment = cbxLength.SelectedItem * 12
End If
DongGyoun