PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms Form's KeyDown delegate not called when in DropDownList ComboBox

Reply

Form's KeyDown delegate not called when in DropDownList ComboBox

 
Thread Tools Rate Thread
Old 19-06-2004, 03:06 PM   #1
=?Utf-8?B?U2NvdHQ=?=
Guest
 
Posts: n/a
Default Form's KeyDown delegate not called when in DropDownList ComboBox


I have a form with a delegate set up for the KeyDown event. I have set KeyPreview=true and the delegate is called correctly whenever I press a key, except if the active control on that form is a DropDown ComboBox.

If I change that ComboBox to be DropDownStyle=ComboBoxStyle.DropDowList the delegate fires when I press a key in that control, as I would expect. The problem is I don't want to restrict the ComboBox to a fixed list of options. The user needs to be able to select, or type their own option.

I have reproduced this in an extremely trivial app - one form, two comboboxes, one delegate, and no databinding etc. Does anyone know whether I could be doing something else that has created this problem, or whether this is a known bug? I have searched but can't find a post that seems relevant.

Thanks,
Scott.
  Reply With Quote
Old 20-06-2004, 09:08 PM   #2
Ruslan Trifonov
Guest
 
Posts: n/a
Default Re: Form's KeyDown delegate not called when in DropDownList ComboBox

I reproduced this exactly as you've described.
The only work around I see is to assign the form's delegate to the dropdown
lists' KeyDown event
hope you do not have too much dropdown lists on the form


  Reply With Quote
Old 21-06-2004, 07:15 AM   #3
Ying-Shen Yu[MSFT]
Guest
 
Posts: n/a
Default RE: Form's KeyDown delegate not called when in DropDownList ComboBox

Hi Scott,

I can reproduce this issue on my system too,
It seems this behavior is inconsistent with the same scenario in VB6.
I'll forward this issue to the product team to let them investigate it.
In the meantime, you may try workaround to see if could resolve this
problem:
<code>
class MyComboBox : ComboBox
{
protected override bool ProcessKeyEventArgs(ref Message m)
{
if ( this.DropDownStyle == ComboBoxStyle.DropDown &&
this.ProcessKeyPreview ( ref m ) )
{
return true;
}
return base.ProcessKeyEventArgs (ref m);
}
}
</code>

Please feel free to reply this thread if you still have problem on this
issue.

Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.

  Reply With Quote
Old 21-06-2004, 12:45 PM   #4
=?Utf-8?B?U2NvdHQ=?=
Guest
 
Posts: n/a
Default RE: Form's KeyDown delegate not called when in DropDownList ComboB

Yes. That works for me.
I'm not exactly sure what it is doing, but assume this is the magic couple of lines of code that is missing from the ComboBox control.

I also had success with wiring up the KeyDown event for each DropDown style ComboBox, but as the previous reply points out, this is quite tedious if you have more than a couple.

Is this something MSFT is likely to fix in a .Net Framework update or do we wait for Longhorn?

Thanks for your help,
Scott.



""Ying-Shen Yu[MSFT]"" wrote:

> Hi Scott,
>
> I can reproduce this issue on my system too,
> It seems this behavior is inconsistent with the same scenario in VB6.
> I'll forward this issue to the product team to let them investigate it.
> In the meantime, you may try workaround to see if could resolve this
> problem:
> <code>
> class MyComboBox : ComboBox
> {
> protected override bool ProcessKeyEventArgs(ref Message m)
> {
> if ( this.DropDownStyle == ComboBoxStyle.DropDown &&
> this.ProcessKeyPreview ( ref m ) )
> {
> return true;
> }
> return base.ProcessKeyEventArgs (ref m);
> }
> }
> </code>
>
> Please feel free to reply this thread if you still have problem on this
> issue.
>
> Thanks!
>
> Best regards,
>
> Ying-Shen Yu [MSFT]
> Microsoft Community Support
> Get Secure! - www.microsoft.com/security
>
> This posting is provided "AS IS" with no warranties and confers no rights.
> This mail should not be replied directly, please remove the word "online"
> before sending mail.
>
>

  Reply With Quote
Old 22-06-2004, 03:09 AM   #5
Ying-Shen Yu[MSFT]
Guest
 
Posts: n/a
Default RE: Form's KeyDown delegate not called when in DropDownList ComboB

Hi Scott,

I'm glad to see the workaround could resolve your problem,

I have forward to our product group, they will investigate it further and
decide how to fix it and do complete tests, since the process was just
began, it's hard to say which release will include this fix.

Thanks for your understanding.

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off