Creating a Mulicolumn list in the VB6.0 combo box.

Posted on 2003-03-12
Medium Priority
Last Modified: 2012-05-04
I using VB6.0 with WIN2000. How do you create a multicolumn list in the combo box that comes with VB6.0?

The MS 2.0 Forms combo box has a multicolumn combo box and works fine.  But using this combo box requires that a computer have MSOffice on the user computer.  I wish to distribute my software on WIN98 and WIN2000 systems where some of these systems have MSWorks instead of MSOffice.  Note:  The MS 2.0 Forms combo box requires the FM20.dll be on the user computer.  

I have the following data is to be placed in the VB6.0 combo box:

   Column 1        Column 2
  Truck Code       Description
  GMC             General Motors
  FRD             Ford Motor Company

I also need to know how do you extend the width of the combo box list?

The Firebird

Question by:BirdsOfFire1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 11

Accepted Solution

supunr earned 750 total points
ID: 8123753
well, one way to get around this problem is use code similar to below.  set the font style of the combo box to fix width font such as "Courier new" and then

Option Explicit

Private Sub Combo1_Click()
    Combo1.Width = 3000
End Sub

Private Sub Combo1_DropDown()
    Combo1.Width = 5000
End Sub

Private Sub Combo1_LostFocus()
    Combo1.Width = 3000
End Sub

Public Function PadR(str As String, chars As Integer, Optional right As Integer) As String

'   pad a string with spaces at the end of the string (ie right justify)
'   ----------------------------------------------------------------------

    Dim i As Integer
    On Local Error Resume Next
    PadR = ""
    If (Len(str) > chars) Then
        PadR = str
        PadR = PadR & Space(chars - Len(str) - right)
        PadR = PadR & str
        PadR = PadR & Space(right)
    End If

End Function

Public Function PadL(str As String, chars As Integer, Optional iLeft As Integer) As String

'   pad a string with spaces at the begining of the string (ie left justify)
'   ------------------------------------------------------------------------

    Dim i As Integer
    On Local Error Resume Next
    PadL = ""
    If (Len(str) > chars) Then
        PadL = str
        PadL = PadL & Space(iLeft)
        PadL = PadL & str
        PadL = PadL & Space(chars - Len(str) - iLeft)
    End If

End Function

Private Sub Form_Load()
    Combo1.AddItem PadR("GMC", 3) & " : " & PadL("General Motors", 20)
    Combo1.AddItem PadR("FRD", 3) & " : " & PadL("Ford Motor Company", 20)
    ' etc.
End Sub

This is only a workaround and I don't think is a neat solution.  But might suit your purpose.

Good Luck!

Expert Comment

ID: 8123840
why not use listview control?

Expert Comment

ID: 8126195

Here is an article (with source code) that shall help you:

"Substituting a ListView for a Combo's Dropdown List"


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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

765 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