detecting combobox list closure
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.windowsforms.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

adam@twv.org (VIP)
Is there a way of detecting when a combobox list closure?

The DropDown event only fires when the list opened not when it is closed,
for example by the user clicking outside the combobox.

I wondered about deriving a class from ComboBox and overriding WndProc to
look for whatever message it must receive on closing.

Does anyone have any code samples or know where I can find a reference for
these messages?

Thanks

Adam

Reply to this message...
 
    
Imran Koradia (VIP)
You are right on track. I don't have a complete code sample on hand but
here's how you can go about it:

Create a new inherited control that inherits from ComboBox. In the new
control, override the WndProc method as follows:

Private Const CB_SHOWDROPDOWN As Integer = &H14F

Protected Overrides Sub WndProc( _
ByRef m As Message)
if m.Msg = CB_SHOWDROPDOWN then
if CBool(m.WParam) = True then
Console.WriteLine("showing listbox of combobox")
else
Console.WriteLine("hiding listbox of combobox")
end if
end if
End Sub

The constant values are in the header winuser.h. Here's a link about the
CB_SHOWDROPDOWN message:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/comboboxes/comboboxreference/comboboxmessages/cb_showdropdown.asp

hope that helps..
Imran.

"Click here to reveal e-mail address" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Imran Koradia (VIP)
Ofcourse, don't forget to call MyBase.WndProc at the end of the procedure so
that the messages are sent to the base control or else your combobox won't
work at all!

[Original message clipped]

Reply to this message...
 
    
adam@twv.org (VIP)
Thanks for this.

I have tried it. One problem was that despite the docs saying that wParam is
a bool, it throws an invalidCast exception when you try to convert it, but I
got round that with IntPtr.ToInt32().

However, the more significant problem is that the combobox doesnt seem to
receive a message, at least not CB_SHOWDROPDOWN when it closes, only when it
opens. My reading of the docs is that this is the right message, with
different values in wParam depending on whether it is opening or closing.

Does anyone know which is the message to close the dropdown?

Adam

"Imran Koradia" wrote:

[Original message clipped]

Reply to this message...
 
 
System.Console
System.IntPtr
System.Windows.Forms.ComboBox




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com