Using CBN_CLOSEUP to give another Combobox focus

viatorg

New member
Joined
Jul 15, 2003
Messages
3
Location
Charleston, SC
Hi all,

Trying to make a combobox get focus when you left click on another combobox while the list part is down of the other combobox. It takes two clicks now to give another combobox focus. I was thinking I could make the control have focus
where the cursor location is when I Left Mouse Down?
When you left mouse down or when the list part retracts
from the combo that you are on I could then catch
CBN_CLOSEUP, but doesnt seam to send the message all the time?

I have done alot of searching and find people telling to look at MSDN, but havent found that to be very helpful or any samples to see how to use this in VB.NET.

Can someone please help

Public Class MyComboBox
Inherits System.Windows.Forms.ComboBox

Private Const CBN_DROPDOWN = 7
Private Const CBN_CLOSEUP = 8
Private Const WM_COMMAND As Long = &H111
Private Const WM_LBUTTONDOWN As Integer = &H201 513

Public First As Boolean = False
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)


If m.Msg = CBN_CLOSEUP Then
Console.Write(m.Msg & " ComboBox Retracting List" & vbCrLf)

Maybe do something here to give control focus where
the cursor is located.

End If

MyBase.WndProc(m)


End Sub

End Class

Thanks
Gerry
 
why not do something like this :
Code:
    Private Sub ComboBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ComboBox1.MouseDown
        If ComboBox1.SelectedIndex <> -1 Then
            If e.Button = MouseButtons.Left Then
                ComboBox2.Focus()
            End If
        End If
    End Sub

    Private Sub ComboBox2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ComboBox2.MouseUp
        If ComboBox1.SelectedIndex <> -1 Then
        /// add any code here to retrieve the combo item from ComboBox1.    
        ComboBox1.SelectedIndex = -1
        End If
    End Sub
 
Thanks for your help, but that
doesnt work.

While combobox1 list is being displayed and
you mouse over and click combobox2. Combobox2 doesnt get focus until you click again.

Any other help would be great.

Thanks
Gerry
 
Try using form.GetChildtAtPoint(CursorPoint as point) at that should return the control you want. Then set the use that control to call focus to itself.
 
Back
Top