URGENT: Tab Stops in Combobox

I am trying to set some tab stops in a combobox.

Using the following code, I obtain the handle for the list of the combo and attempt to set the tabstops ...

Public Const GWL_EXSTYLE As Long = (-20)
Public Const WS_EX_RIGHT As Long = &H1000
Public Const WS_EX_LEFTSCROLLBAR As Long = &H4000
Public Const CB_SHOWDROPDOWN = &H14F

Public Enum AlignConstants
   alignLeft = 0
   alignRight = 1
End Enum

' *** Declared elsewhere in my mods - unproc to use
'Public Type RECT
'   Left As Long
'   Top As Long
'   Right As Long
'   Bottom As Long
'End Type

   cbSize As Long
   rcItem As RECT
   rcButton As RECT
   stateButton  As Long
   hwndCombo  As Long
   hwndEdit  As Long
   hwndList As Long
End Type

Public Declare Function GetWindowLong Lib "user32" _
   Alias "GetWindowLongA" _
  (ByVal hwnd As Long, _
   ByVal nIndex As Long) As Long

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

Public Declare Function SendMessage Lib "user32" _
   Alias "SendMessageA" _
  (ByVal hwnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Any) As Long

Public Const LB_SETTABSTOPS = &H192

Public Sub SetCboTabs(cb As ComboBox)
  'set up the tabstops in the list boxes
   ReDim TabStop(0 To 2) As Long
  'assign some values to the tabs for the second third and fourth
  'column (the first is flush against the listbox edge)
   TabStop(0) = 90
   TabStop(1) = 130
   TabStop(2) = 185
   'Debug.Print GetComboListHandle(cb)
  'clear then set the tabs
   Call SendMessage(GetComboListHandle(cb), LB_SETTABSTOPS, 0&, ByVal 0&)
   Call SendMessage(GetComboListHandle(cb), LB_SETTABSTOPS, 3, TabStop(0))

End Sub

Public Function GetComboListHandle(ctl As ComboBox) As Long


   CBI.cbSize = Len(CBI)
   Call GetComboBoxInfo(ctl.hwnd, CBI)
   GetComboListHandle = CBI.hwndList

End Function

The code was modified from a mvps code - cant remember who or where I got it from. I have never been able to get it to work properly ...

Can anyone can help me get the code to work, or provide alternative coding ... ?

All help appreciated.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I don't think you can send a ListBox Message to a ComboBox. Here are some examples from Randy Birch that subclass the combobox to display a listbox or listview instead.


Another option would be to use a fixed width font in the combobox and create a Sub routine to add the items to the combobox. Here is a basic example that will add 3 columns to a combobox by checking the items length and padding spaces on the end. The sub will set the combobox box font to Courier. You could adjust that to any fixed width font.

Private Sub Command1_Click()
AddComboItem Combo1, "Col 1", "Col 2", "Col 3"
AddComboItem Combo1, "Column1", "Column2", "Column3"
AddComboItem Combo1, "Column # 1", "Column  # 2", "Column # 3"
End Sub

Private Sub AddComboItem(cBox As ComboBox, Col1 As String, Col2 As String, Col3 As String)
Dim ColWid1 As Integer, ColWid2 As Integer, ColWid3 As Integer
Dim Spacer As String
' set col width in spaces here
ColWid1 = 10
ColWid2 = 20
ColWid3 = 25

' set to a common fixed width font
cBox.Font = "Courier"

If ColWid1 > Len(Col1) Then
    Spacer = Space$(ColWid1 - Len(Col1))
    Col1 = Col1 & Spacer
    Col1 = Left$(Col1, ColWid1)
End If

If ColWid2 > Len(Col2) Then
    Spacer = Space$(ColWid2 - Len(Col2))
    Col2 = Col2 & Spacer
    Col2 = Left$(Col2, ColWid2)
End If

If ColWid3 > Len(Col3) Then
    Spacer = Space$(ColWid3 - Len(Col3))
    Col3 = Col3 & Spacer
    Col3 = Left$(Col3, ColWid3)
End If

cBox.AddItem Col1 & Col2 & Col3

End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.