Home All Groups Group Topic Archive Search About

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

Author
8 Aug 2006 1:07 PM
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!

Author
8 Aug 2006 2:10 PM
Larry Lard
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).

--
Larry Lard
larryl***@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Author
8 Aug 2006 3:05 PM
Claes Bergefall
Show quote Hide quote
"Larry Lard" <larryl***@googlemail.com> wrote in message
news:4jrkb3F92c6iU1@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
Author
9 Aug 2006 4:16 AM
Steve Marshall
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!
Author
9 Aug 2006 10:47 AM
Larry Lard
Claes Bergefall wrote:
Show quoteHide quote
> "Larry Lard" <larryl***@googlemail.com> wrote in message
> news:4jrkb3F92c6iU1@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.


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