Reputation: 896
Pressing Enter key clears text of ComboBox
when drop down is open in a ComboBox
with AutoCompleteMode
set to Append
.
We know in widows forms when the AutocompleteMode
property in the ComboBox
is set to Append
then we get the values before we type the complete text of an item.
Problem is here:
How can I have Append
option and also make pressing Enter when the Dropdown is open, keep entered text and don't remove it.
I tried the None option in the "Auto complete Mode" property it is working fine but there is no append of data....
I dont need the suggest and suggest append options in the "Auto complete Mode" property since it opens another dropdown window....
I need to type data while the data in the dropdown box is listed and when i get the append values just by clicking enter button it should work(without getting deleted)...
Is this possible?
Thanks
Upvotes: 4
Views: 4562
Reputation: 9
In vb.NET, you must do it in event keydown
:
Private Sub ComboBox2_KeyDown(sender As Object, e As KeyEventArgs) Handles ComboBox2.KeyDown
If e.KeyCode = Keys.Enter Then TextBox7.Focus()
End Sub
Upvotes: 0
Reputation: 125277
When the dropdown is closed, it works as expected, but when the dropdown is open, pressing Enter closes the dropdown and removes entered text.
As a solution you can derive from ComboBox
and override IsInputKey
this way:
public class MyComboBox : ComboBox
{
protected override bool IsInputKey(Keys keyData)
{
switch ((keyData & (Keys.Alt | Keys.KeyCode)))
{
case Keys.Enter:
case Keys.Escape:
if (this.DroppedDown)
{
this.DroppedDown = false;
return false;
}
break;
}
return base.IsInputKey(keyData);
}
}
Upvotes: 6