• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 624
  • Last Modified:

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

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?



Thanks
The Firebird



 
 
0
BirdsOfFire1
Asked:
BirdsOfFire1
1 Solution
 
supunrCommented:
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
    Else
        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
    Else
        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!
0
 
manduz_griffusCommented:
why not use listview control?
0
 
marconovaroCommented:

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

"Substituting a ListView for a Combo's Dropdown List"
http://www.mvps.org/vbnet/code/subclass/combolistview.htm

HTH
M
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now