Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview/combobox control

Status
Not open for further replies.

JonnyV

Programmer
Mar 4, 2002
7
0
0
CA
Hey all

I'm looking for a combobox style treeview control, that is, a control that looks (and acts) like a combobox but drops down into a treeview instead of a simple list.

Thx in advance,
Jon
 
Do it yourself. Look at the Datetime picker. That is a combo box with a 2nd control that just pops up when they click the down arrow.
 
Thanks, but no thanks, unless there's an API call to disable the drop down effect on the combobox.
=/
 
Wow, I usually have very good responses here, so this has been disappointing..!

=/

Thanks anyway fellas,
Jon
 
Use a hook. Drop the following into a public module:

Option Explicit

Public mp_lpPrevWndProc As Long
Public Const GWL_WNDPROC As Long = -4

Private Const CBN_DROPDOWN As Long = 7

Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private m_ctlCombo As ComboBox

Public Sub Unhook_Combo(hwnd As Long)
If mp_lpPrevWndProc <> 0 Then
Call SetWindowLong(hwnd, GWL_WNDPROC, mp_lpPrevWndProc)
mp_lpPrevWndProc = 0
End If
End Sub

Public Sub Hook_Combo(hwnd As Long, ByRef ctlCombo As ComboBox)
If mp_lpPrevWndProc = 0 Then
Set m_ctlCombo = ctlCombo
mp_lpPrevWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End If
End Sub

Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
If hwnd = m_ctlCombo.hwnd Then
Select Case uMsg
Case CBN_DROPDOWN
WindowProc = 1
Case Else
WindowProc = CallWindowProc(mp_lpPrevWndProc, hwnd, uMsg, wParam, lParam)
End Select
End If
End Function

And add this to the Form_Load event:

If mp_lpPrevWndProc = 0 Then Hook_Combo Combo1.hwnd, Combo1

And this to the Form_Unload event:

If mp_lpPrevWndProc <> 0 Then Unhook_Combo Combo1.hwnd

Do not mess with the code in the WindowProc proceedure when the program is running and make sure you stop the program properly.

After each time that the combo gets the focus, it will work once. Assumming you will add a TreeView and move the Focus there on the click, there shouldn't be a problem.

If you use a different type of combo box, such as the DataCombo, you will need to change the variable:

Private m_ctlCombo As ComboBox

to

Private m_ctlCombo As DataCombo
[/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top