Results 1 to 8 of 8

Thread: Columns inside a listbox?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    156

    Columns inside a listbox?

    I heard someone mentioning that it's possible to create columns inside a list box? How do i do this?
    If it's not possible, then what control do you guys think is the best for creating options box with columns? (like when you put A,B,C,D inside a combo box, but with columns)

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Columns inside a listbox?

    Yoou can mimic columns in listbox by setting TabStop but better way is substitute ordinary listbox with Listview control.
    In case you still want to use Listbox then here is a sample:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function SendMessage Lib "user32" _
    4.    Alias "SendMessageA" _
    5.    (ByVal hwnd As Long, _
    6.     ByVal wMsg As Long, _
    7.     ByVal wParam As Long, _
    8.     lParam As Any) As Long
    9.  
    10. Private Const LB_SETTABSTOPS = &H192
    11.  
    12.  
    13. Private Sub Command1_Click()
    14.     List1.AddItem "Column1" & vbTab & "Column2" & vbTab & "Column3"
    15.     List1.AddItem "Column1" & vbTab & "Column2" & vbTab & "Column3"
    16.     List1.AddItem "Column1" & vbTab & "Column2" & vbTab & "Column3"
    17.     List1.AddItem "Column1" & vbTab & "Column2" & vbTab & "Column3"
    18. End Sub
    19.  
    20. Private Sub Form_Load()
    21.  
    22.   'set up the tabstops in the list boxes
    23.    ReDim TabStop(0 To 2) As Long
    24.  
    25.   'assign some values to the tabs for the second third and fourth
    26.   'column (the first is flush against the listbox edge)
    27.    TabStop(0) = 60
    28.    TabStop(1) = 120
    29.    TabStop(2) = 180
    30.  
    31.   'clear then set the tabs
    32.    Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 0&, ByVal 0&)
    33.    Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 3, TabStop(0))
    34.    List1.Refresh
    35.  
    36. End Sub

  3. #3
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: Columns inside a listbox?

    The ListView would be my vote.
    "It's cold gin time again ..."

    Check out my website here.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    156

    Re: Columns inside a listbox?

    Thanks!
    Sorry but i'm still new... how do i create listview control? it's not in the standard toolbar right? I know i should use "Add components" but which one should i choose? I didn't see listview or something like that..

  5. #5

  6. #6

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    156

    Re: Columns inside a listbox?

    Thanks!

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Columns inside a listbox?

    This might help as well as RhinoBull's example:

    ListView Tutorial

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