Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

.Net combo box - what is "opposite" of DropDown event?

25 views
Skip to first unread message

Steve Marshall

unread,
Aug 8, 2006, 9:07:39 AM8/8/06
to
I'm working on an owner-drawn combo box which has extended
functionality. I have to do something to the dropdown list when it
drops down, then undo it when it is closed up again. But I can't see
an event which seems to be a "CloseUp" event - is there such an event?
Surely there must be!

Larry Lard

unread,
Aug 8, 2006, 10:10:43 AM8/8/06
to

.NET 2.0: DropDownClosed
Earlier: Override the WndProc message and watch for message
CB_SHOWDROPDOWN (this same message is sent on both drop and close, so it
only means 'close' when it's sent while the dropdown is dropped down).

--
Larry Lard
larr...@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version

Claes Bergefall

unread,
Aug 8, 2006, 11:05:49 AM8/8/06
to

"Larry Lard" <larr...@googlemail.com> wrote in message
news:4jrkb3F...@individual.net...

> Steve Marshall wrote:
>> I'm working on an owner-drawn combo box which has extended
>> functionality. I have to do something to the dropdown list when it
>> drops down, then undo it when it is closed up again. But I can't see
>> an event which seems to be a "CloseUp" event - is there such an event?
>> Surely there must be!
>
> .NET 2.0: DropDownClosed
> Earlier: Override the WndProc message and watch for message
> CB_SHOWDROPDOWN (this same message is sent on both drop and close, so it
> only means 'close' when it's sent while the dropdown is dropped down).
>

CB_SHOWDROPDOWN is not a notification message. It's used to drop down the
list programatically. To know when the list closes up you should use the
CBN_CLOSEUP notification. Here's the code for that:

Public Class ComboBoxEx
Inherits ComboBox
Private Const WM_USER As Integer = &H400
Private Const WM_COMMAND As Integer = &H111
Private Const OCM__BASE As Integer = WM_USER + &H1C00
Private Const OCM_COMMAND As Integer = OCM__BASE + WM_COMMAND

Private Function HIWORD(ByVal value As Integer) As Short
Return CShort(New System.Drawing.Point(value).Y)
End Function

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = OCM_COMMAND Then
Dim code As Integer = HIWORD(m.WParam.ToInt32)
If code = CBN_CLOSEUP Then
OnCloseUp(EventArgs.Empty)
End If
End If
MyBase.WndProc(m)
End Sub

Protected Overridable Sub OnCloseUp(ByVal e As System.EventArgs)
RaiseEvent CloseUp(Me, e)
End Sub

Public Event CloseUp As EventHandler
End Class

/claes


Steve Marshall

unread,
Aug 9, 2006, 12:16:44 AM8/9/06
to
Many thanks Claes. I had tried what Larry suggested, but my WndProc
override routine never saw the CB_SHOWDROPDOWN message, so I was about
to post a further question about it. Your contribution is perfectly
timed!

Larry Lard

unread,
Aug 9, 2006, 6:47:57 AM8/9/06
to
Claes Bergefall wrote:
> "Larry Lard" <larr...@googlemail.com> wrote in message
> news:4jrkb3F...@individual.net...
>> Steve Marshall wrote:
>>> I'm working on an owner-drawn combo box which has extended
>>> functionality. I have to do something to the dropdown list when it
>>> drops down, then undo it when it is closed up again. But I can't see
>>> an event which seems to be a "CloseUp" event - is there such an event?
>>> Surely there must be!
>> .NET 2.0: DropDownClosed
>> Earlier: Override the WndProc message and watch for message
>> CB_SHOWDROPDOWN (this same message is sent on both drop and close, so it
>> only means 'close' when it's sent while the dropdown is dropped down).
>>
>
> CB_SHOWDROPDOWN is not a notification message. It's used to drop down the
> list programatically. To know when the list closes up you should use the
> CBN_CLOSEUP notification. Here's the code for that:

That's what I deserve for skimming API docs too quickly, I suppose.
Thanks for sorting me out.

0 new messages