Help with KeyPress on comboBox! Code included!

  • Thread starter Thread starter Keith Smith
  • Start date Start date
K

Keith Smith

Ok, I have been researching this problem for the past two hours (at least!)
and I just can't seem to figure it out. So I broke down and decided to post
some code for some of you gurus to look at.

When running the code, don't forget to add the autoCompleteComboBox.dll file
which is included.

I hope it's not inappropiate to post code here. Please let me know if it
is.

On the surface the code really isn't that complicated. It works like
this...

1) The user presses F3
2) The KeyUp event is lauched (on the form) and the comboBoxes are cleared
(not the actual items, but the top part - where the user types).

But it doesn't seem to work. Help!

You can download my code file here...
http://www.mnik.com/temp/app1.zip
 
Hi!
The problem is that the keypreview doesn't work with comboboxes.
So, you must use the event KeyUp from every combobox.
Hope that helps.
Best regards.
 
There's something wrong with the AutoCompleteComboBox, in order to get the
code to work properly I had to set the text = "" twice...

private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode==Keys.F3)
{
e.Handled = ClearComboBox ( autoCompleteComboBox1 )
|| ClearComboBox ( autoCompleteComboBox2 );
}
}

private bool ClearComboBox( AutoCompleteComboBox.AutoCompleteComboBox
accb )
{
if ( accb.Focused )
{
accb.SelectAll();
accb.Refresh();
accb.Text = "";
accb.Text = "";
return true;
}

return false;
}


Hope that helps.

Dan.
 
Back
Top