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

  • Thread starter Thread starter Steve Marshall
  • Start date Start date
S

Steve Marshall

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!
 
Steve said:
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).
 
Larry Lard said:
.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
 
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!
 
Claes said:
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.
 
Back
Top