|
-
September 28th, 2010, 03:39 PM
#1
[RESOLVED] KeyPress, KeyCode handling behavior strange
Hi all,
I basically want to have a combo that lists some account codes (e.g ALB1E, BSE2F) and when the user types the first few letters and presses enter, I calla function that will get all matching acocunt codes (e.g when they type ALB, it will show all ALB%) and populate them in a combo.
The problem is when I handle e.keycode == Enter, it gets called TWICE and the resulting is a wrong search results.
Code:
private void cmbAccountCodes_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
GetDeliveryPoints(cmbAccountCodes.Text.Trim()); //gets the data I want to populate and adds it to the combo as well
}
}
So, when I press ALB and press Enter, it egts matching results like ALB10Q, ALB67Y, ALB40W etc and populates them in a combo. But then, this method gets called again somehow, and this time the first item in the combo is selected ( int his case its ALB10Q) and then it searches again for ALB10Q% passing it as param to GetDeliveryPoints() which I do not want. Why is the KeyDown method called twice? Thanks for the help.
-
September 28th, 2010, 03:46 PM
#2
Re: KeyPress, KeyCode handling behavior strange
Ok, I fixed this error a min after I posted it -- but its still strange.
So, GetDeliveryPoints() had this statement: cmbAccountCodes.DroppedDown = true;
This was causing the keydown event somehow to be called twice. I commented this and now it works fine!! Any inputs would still be a learning though on this.
-
September 29th, 2010, 08:57 AM
#3
Re: KeyPress, KeyCode handling behavior strange
In vb I would have done it through the form's keyup.
-
September 29th, 2010, 08:59 AM
#4
Re: KeyPress, KeyCode handling behavior strange
What I just said wasn't true. Disregard that unless you like pain.
-
September 29th, 2010, 10:13 AM
#5
Re: KeyPress, KeyCode handling behavior strange
 Originally Posted by viperbyte
What I just said wasn't true. Disregard that unless you like pain.
Thanks for the inputs though. As I said, I fixed it by commenting out the droppeddown statement. I understand it as when a combobox drops down it generates drop down event which also is an equivalent of Enter or a combo of LButton + MBUtton and Back or something like that , hence a combo dropdown = Enter key value. So, any code written for handling Enter in a combo, will also be invoked when it drops down.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|