Re: [2005] combobox question
2 Code:
Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles ComboBox1.KeyDown
If e.KeyCode = Keys.Enter And Me.ComboBox1.Text <> String.Empty Then
MessageBox.Show(Me.ComboBox1.Text)
End If
End Sub
Re: [2005] combobox question
vb Code:
private sub comboBox1_KeyPress(sender as object, e as KeyEventArgs)
if e.KeyCode = Keys.Enter then messageBox.show(combobox1.text)
end sub
Re: [2005] combobox question
Code:
Private Sub cbDisplay_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cbDisplay.KeyDown
If e.KeyCode = Keys.Enter Then
MsgBox(cbDisplay.Text)
End If
End Sub
Re: [2005] combobox question
talkro and robertx,
When I use your code, I get a blank message box.
Re: [2005] combobox question
That's because there is no text in the combo box. Use stimbo's code which tests for an empty string and does not display a message box if there is no text displayed.
Re: [2005] combobox question
robertx,
stimbo's code returns nothing even when I have text in the combo box
Re: [2005] combobox question
Charming,
You are simply doing something wrong then.
I noticed in your code you have a keypress address but a key down handle which could be causing a problem.
Re-create the subroutine and try again. Everybody's code is correct, mine just had that extra check of not showing the messagebox if the combobox was empty.
Re: [2005] combobox question
stimbo,
My dropdownstyle is set to "simple". This is the monkey throwing the wrench. Can you think of a work around for this?
Thank you for you help :wave:
Re: [2005] combobox question
I would imagine that the event still fires no matter what the dropdown style is.
Although I seem to remember having a problem with events firing twice depending on menu style. If that's the case then you could try putting the code in the Key Up event instead.
Re: [2005] combobox question
the Key Up event does not work either. When I press "Enter", the all the text is cleared from the box.
Re: [2005] combobox question
Sigh. Could you show us exactly what code you have now.
Re: [2005] combobox question
Sure,
The below code works if the combo box is set to "DropDown". If it is set to "Simple" (the style that I need) then it does not work.
Code:
Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles ComboBox1.KeyDown
If e.KeyCode = Keys.Enter And Me.ComboBox1.Text <> String.Empty Then
MessageBox.Show(Me.ComboBox1.Text)
End If
End Sub
Re: [2005] combobox question
It works for me when set to simple. Although it does fire twice as I thought it might. One workaround for that would be put it in the keyUp event as I said although you can't get it to work at all which is very strange.
I'm out of ideas. Anyone else have a problem with it firing the Dropdown style is set to Simple? Could it be a service pack issue? (Clutching at straws now)
Re: [2005] combobox question
bah, I am still trying to get this thing to work. Thank you for your help though stimbo, much appreciated.
Does anyone have any ideas about this? :(