Vinchenzo,
That works perfectly. It took me a few minutes to undertstand that I needed
to add a timer control to the form - I've never used one before.
Thanks a lot,
Doug
"Vinchenzo vinç" <
vbvinchenz0@BORRARhotmail.com>wrote in message
"Doug Glancy" <
nobodyhere@replytogroup.com>escribió en el mensaje
Quote
With a VB 6 Combobox (type 2) I was hoping to set the selected item to the
3rd item from the top when the dropdown is clicked. I read that the
TopIndex property doesn't work with a type 2. My first question is, does a
SendMessage CB_TopIndex call work with such a combob?. If so, then can
somebody tell me how to do it?
Both API message and intrinsic property works for the 'Style 2', the
problem is that the list must be open before you set the property or send
the message. This means that execution needs exit from the '_DropDown' event
to be able to send the message, or set the property.
The easiest solution to this "problem" is enabling a 'Timer' in the
'_DropDown' event, waiting in the '_Timer' event until the list becomes
dropped, state which you can retrieve sending the CB_GETDROPPEDSTATE message
to the 'ComboBox'.
For example, see the changes:
'******************
Quote
'In the Form
Private Sub cboTimeIncrement_DropDown()
Timer1.Interval = 10
Timer1.Enabled= True
Private Sub Timer1_Timer()
Timer1.Enabled = False
Do Until IsCBListDropped(cboTimeIncrement.hwnd) = True
DoEvents
Loop
With Me.cboTimeIncrement
'Set the property or send the message, is just the same
.TopIndex = IIf(.ListIndex - 2>= 0, .ListIndex - 2, 0)
'Debug.Print cbo_set_topindex(Me.cboTimeIncrement, IIf(.ListIndex -
2>= 0, .ListIndex - 2, 0))
End With
End Sub
'__________________________________
Quote
'In a separate code module
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) As Long
Private Const CB_SETTOPINDEX As Long = &H15C
Public Const CB_GETDROPPEDSTATE As Long = &H157
Quote
Public Function cbo_set_topindex(cbo As ComboBox, top_index As Long) As
Long
cbo_set_topindex = SendMessage(cbo.hwnd, CB_SETTOPINDEX, top_index, 0)
End Function
Public Function IsCBListDropped(ByVal lngHWND As Long) As Boolean
IsCBListDropped = SendMessage(lngHWND, CB_GETDROPPEDSTATE, ByVal 0&,
ByVal 0&)
End Function
'******************
--
Greetings
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
( ! ) Preceding answers in Google:
groups.google.com/group/microsoft.public.vb.general.discussion">
groups.google.com/group/microsoft.public.vb.general.discussion
( i ) Temperance in the forum:
www.microsoft.com/communities/conduct/default.mspx">
www.microsoft.com/communities/conduct/default.mspx
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-