I have a form with A GroupBox on it. Within the GroupBox is a TextBox and a ComboBox. I am trying to disable one or the other when either text is entered into the textbox OR when an item has been selected in the combobox.
I can get the combobox to become disabled by using the TextChanged event in the textbox control. If I select an item in the combobox control it will disable the textbox using the SelectedIndex event, however if I delete the selection manually, I cannot get the textbox to become enabled and the combobox to become disabled.
This is the code I have so far:
Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
If TextBox5.Text <> "" Then
ComboBox1.Enabled = False
Else
ComboBox1.Enabled = True
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedIndex = -1 Then
TextBox5.Enabled = True
ElseIf ComboBox1.SelectedIndex <> -1 Then
TextBox5.Enabled = False
End If
End Sub