-
ComboBox Help
How to I have an if statement depending on the combo box selection? I get this message:
Conversion from string "Clear" to type 'Double' is not valid.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ComboBox1.SelectedIndex = "Clear" Then
TextBox1.Clear()
ElseIf ComboBox1.SelectedIndex = "Disable" Then
TextBox1.Enabled = False
ElseIf ComboBox1.SelectedIndex = "Both" Then
TextBox1.Clear()
TextBox1.Enabled = False
End If
End Sub
Thanks in advance for the help.
-
Re: ComboBox Help
The SelectedIndex property returns the index of the selected item, which is an Integer N in the range 0 <= N < Items.Count. If you want the actual text displayed in the control then use the Text property. You might also use the SelectedItem or SelectedValue property, which may both contain the same value as the Text property but may not, depending on the circumstances.
By the way, you would also be better to use a Select Case statement than If...ElseIf in that situation.