URGENT: Tab Stops in Combobox

Posted on 2006-04-11
Medium Priority
Last Modified: 2008-02-01
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.


Question by:dwe0608
  • 2
LVL 28

Expert Comment

ID: 16432488
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.


LVL 28

Accepted Solution

vinnyd79 earned 2000 total points
ID: 16432605
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

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question