Results 1 to 5 of 5

Thread: List boxes with columns

  1. #1
    Guest

    Post

    Can somebody please help me
    How do you create a list box that uses columns (so that more than one detail of an item added to a list box, can be shown at once).
    I would be very grateful if anyone could help.

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    Post

    'set tab stops in a listbox
    'appears as columns
    '
    Option Explicit
    '
    Public Declare Function SendMessageArray 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

    '<<<<< code for form >>>>>
    '
    Private Sub Command1_Click()

    List1.AddItem "Nothing More"
    List1.AddItem "Nothing Less"
    List1.AddItem "Just A Sample"

    Dim r As Long

    'set up the tabstops in the listboxes
    ReDim TabStop(1 To 3) As Long

    'assign values to the tabs for the second third and fourth
    'column (the first is flush against the listbox edge ie...0)
    TabStop(1) = 80
    TabStop(2) = 160
    TabStop(3) = 240

    'set the tabs
    r = SendMessageArray(List1.hwnd, LB_SETTABSTOPS, 3, TabStop(1))
    List1.Refresh
    List1.AddItem "...A lesson" & vbTab & "in creating" & vbTab & "columns" & vbTab & "in a listbox!"


    End Sub

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    Post

    If you are using a database and datacontrol you can also do this.
    'combine two fields from a database
    'and display them as one field in a listbox
    Dim CombinedFields as String
    Dim strSQL as String

    strSQL = "SELECT *, FirstField & ', ' _
    & SecondField as CombinedFields FROM YourTable;"

    Data1.RecordSource = strSQL
    DbList1.ListField = "CombinedFields"

  4. #4
    New Member
    Join Date
    May 1999
    Location
    El Salvador
    Posts
    6

    Post

    I'm triying to find out how to fill this lists too. If you know something tell me!
    The databound controls let you see the data of a table in a multiple column list but if you don't have it in a table u can't do it.
    Somebody tell me something about an array, could someone help us!

  5. #5
    New Member
    Join Date
    May 1999
    Location
    El Salvador
    Posts
    6

    Post

    Hi!, I finally find out how to do it, it's very simple.
    If you have a listBox, the propertie Columns has the value of the number of columns to show up. In runtime just type
    ListBox1.AddItem Item1 & vbTab & Item2 & vbTab & Item3
    And so on, you just have to insert a Tab between the values you want to put in a List Box. I hope it work for you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width