Results 1 to 29 of 29

Thread: (VB6) How can I have a MultiColumn ListBox? (Emergency)

Hybrid View

  1. #1

    Thread Starter
    Addicted Member javad2000's Avatar
    Join Date
    Dec 2006
    Posts
    238

    Resolved (VB6) How can I have a MultiColumn ListBox? (Emergency)

    Hello

    It's 4 days I'm searching google and asking different people about how to have a "multicolumn" listbox, but nobody could help.

    Some say :"Use a ListView", but I can't find "ListView" in "Components" list.
    Some say : "Add single strings with "vbTab" characters to your "Single-Column" listbox, so that it seems to be "Multicolumn", but this is only useful for specific "Fonts" and doesn't always work properly.
    Some say: Use a DataGrid, but I don't want a grid or table, I want a listbox. (So that when I select a field, the whole record (row) is selected)

    I also tried using "MS-Forms 2.0 Listbox", but all professionals are saying : It has distributional problems. "

    I am getting frustrated. Can anybody please give me a good advice for either adding multicolumn data to a regular listbox or adding a new component to my project that really be a "Multi-column" listbox?

    Thank you very much
    Last edited by javad2000; Dec 20th, 2006 at 12:31 PM.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    You can find the ListView if you go to Projects|Components and select Microsoft Common Controls 6.0.

    I've attached an example that uses it.
    Attached Files Attached Files

  3. #3
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    It's as simple as setting the Columns property to whatever value suits.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    Quote Originally Posted by pnish
    It's as simple as setting the Columns property to whatever value suits.
    Yes but it results in a difficult to manage control.

  5. #5
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    Quote Originally Posted by MartinLiss
    Yes but it results in a difficult to manage control.
    Works for me. But most of the data I display in multiple columns is fixed length. It can get a bit unmanageable with varying length data I agree.
    Quote Originally Posted by javad2000
    It's 4 days I'm searching google and asking different people about how to have a "multicolumn" listbox, but nobody could help.
    The answer to the question is Set the listbox's Column property.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

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

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    Quote Originally Posted by pnish
    The answer to the [javad2000's] question is Set the listbox's Column property.
    No, it isn't - all it does it creates a list with sort of horizontal layout rather than vertical so "columns" are pretty useless - unlike those found in nthe Listview or some Grid control.

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

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    Quote Originally Posted by pnish
    It's as simple as setting the Columns property to whatever value suits.
    It has no value what so ever...
    As Martin mentioned using Listview control is much better option, however take a look at this sample - not exactly columns but imitation.

  8. #8
    Lively Member Mahdi Jazini's Avatar
    Join Date
    Feb 2014
    Location
    Iran / Tehran
    Posts
    89

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    Quote Originally Posted by MartinLiss View Post
    You can find the ListView if you go to Projects|Components and select Microsoft Common Controls 6.0.

    I've attached an example that uses it.
    The examples i have found for the ListView was not clear. but yours was clear

    Thank you for the example

  9. #9
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    I faced a similar problem in the past and this is how it was solved. (credits to Hack)
    Have a like at this post.
    Multi-column Listbox

    Pradeep
    Last edited by Pradeep1210; Dec 10th, 2006 at 01:10 PM.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  10. #10

  11. #11
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    Ahhh, I see that this is a slightly aged thread that got popped.

    I also use the ListView extensively, but I also do occasionally use a ListBox to display columnar data.

    The following are what I use to do that, along with the vbTab character to separate the columns when adding to the ListBox.

    Code:
    
    Option Explicit
    '
    Private 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 Sub SetOneTabStopInListBox(lst As ListBox, ColWidth As Long)
        Dim ColWidths(0 To 0) As Long
        '
        ColWidths(0) = ColWidth
        SetTabStopsInListbox lst, ColWidths()
    End Sub
    
    Public Sub SetTabStopsInListbox(lst As ListBox, ColWidths() As Long)
        Const LB_SETTABSTOPS = &H192
        ' A character is approximately 4 "width" units.
        ' ColWidths() is in character widths of some standard character.
        ' ColWidths() can be either zero or one based.
        ' SADLY: This does not work for listboxes with the style set to checkbox.
        Dim NumCols As Long
        '
        NumCols = UBound(ColWidths) - LBound(ColWidths) + 1 ' Calculate the number of columns.
        SendMessage lst.hWnd, LB_SETTABSTOPS, 0&, ByVal 0& ' Clear any existing tabs.
        SendMessage lst.hWnd, LB_SETTABSTOPS, NumCols, ColWidths(LBound(ColWidths)) ' Set new tabs.
    End Sub
    
    
    
    Enjoy,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  12. #12
    Lively Member Mahdi Jazini's Avatar
    Join Date
    Feb 2014
    Location
    Iran / Tehran
    Posts
    89

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    Quote Originally Posted by Elroy View Post
    Ahhh, I see that this is a slightly aged thread that got popped.

    I also use the ListView extensively, but I also do occasionally use a ListBox to display columnar data.

    The following are what I use to do that, along with the vbTab character to separate the columns when adding to the ListBox.

    Code:
    
    Option Explicit
    '
    Private 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 Sub SetOneTabStopInListBox(lst As ListBox, ColWidth As Long)
        Dim ColWidths(0 To 0) As Long
        '
        ColWidths(0) = ColWidth
        SetTabStopsInListbox lst, ColWidths()
    End Sub
    
    Public Sub SetTabStopsInListbox(lst As ListBox, ColWidths() As Long)
        Const LB_SETTABSTOPS = &H192
        ' A character is approximately 4 "width" units.
        ' ColWidths() is in character widths of some standard character.
        ' ColWidths() can be either zero or one based.
        ' SADLY: This does not work for listboxes with the style set to checkbox.
        Dim NumCols As Long
        '
        NumCols = UBound(ColWidths) - LBound(ColWidths) + 1 ' Calculate the number of columns.
        SendMessage lst.hWnd, LB_SETTABSTOPS, 0&, ByVal 0& ' Clear any existing tabs.
        SendMessage lst.hWnd, LB_SETTABSTOPS, NumCols, ColWidths(LBound(ColWidths)) ' Set new tabs.
    End Sub
    
    
    
    Enjoy,
    Elroy
    Elroy thank you

    Elroy i'm using the listbox in (Microsoft Forms 2.0 Object Library)

    Because it supports unicode and align very well

    Today i have decided to make it multicolumn, but i don't know why addnew adds items from down to up (not up to down) !!!


    Call ListBox2.AddItem(CStr(OBJRS("Summary")), 1)

  13. #13
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    Ahhh Mahdi, I see.

    You've probably been told, but the licensing on the Forms2.0 controls doesn't allow free re-distribution with your package. Also, years ago, for similar reasons, I took a hard look at the Forms2.0 controls as well. However, I found them to be quite glitchy, and just fundamentally buggy on several accounts (improper use of carat, and other problems). IMHO, there are far better options than these Forms2.0 controls.

    I'm not terribly familiar with Krool's stuff, but I know he's got good stuff that he works hard to make bullet-proof. I'd definitely start there, possibly "cutting out" the ListBox if that's all you need/want.

    Also, there are options like this that have been around for a while, and are probably pretty good.

    For my money, I'd stay far away from the Forms2.0.

    Best Of Luck,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  14. #14
    Lively Member Mahdi Jazini's Avatar
    Join Date
    Feb 2014
    Location
    Iran / Tehran
    Posts
    89

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    Quote Originally Posted by Elroy View Post
    Ahhh Mahdi, I see.

    You've probably been told, but the licensing on the Forms2.0 controls doesn't allow free re-distribution with your package. Also, years ago, for similar reasons, I took a hard look at the Forms2.0 controls as well. However, I found them to be quite glitchy, and just fundamentally buggy on several accounts (improper use of carat, and other problems). IMHO, there are far better options than these Forms2.0 controls.

    I'm not terribly familiar with Krool's stuff, but I know he's got good stuff that he works hard to make bullet-proof. I'd definitely start there, possibly "cutting out" the ListBox if that's all you need/want.

    Also, there are options like this that have been around for a while, and are probably pretty good.

    For my money, I'd stay far away from the Forms2.0.

    Best Of Luck,
    Elroy
    I see...

    I have replaced it with listbox of the Krool... it seems it supports unicode...

    Elroy could you put an example for adding multi column data in a classic vb6 listbox?

    is it possible to add 2 or more columns in vb6 classic listbox?

    then i can change its width with your API that you described above

  15. #15
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    Started a project and then put a List1 listbox on it:

    In IDE design mode:

    Name:  Image1.gif
Views: 8547
Size:  9.5 KB

    And then, the code I placed in the form:

    Code:
    
    Option Explicit
    
    Private Sub Form_Load()
        Dim cols(1 To 3) As Long
    
        cols(1) = 25
        cols(2) = 70
        cols(3) = 100
    
        SetTabStopsInListbox List1, cols()
    
    
        List1.AddItem "asdf" & vbTab & "1234124" & vbTab & "zxcv" & vbTab & "piou"
        List1.AddItem "qwer" & vbTab & "1234124" & vbTab & "zxcv" & vbTab & "piou"
        List1.AddItem "fghj" & vbTab & "1234124" & vbTab & "zxcv" & vbTab & "piou"
        List1.AddItem "vbnm" & vbTab & "1234124" & vbTab & "zxcv" & vbTab & "piou"
    
    
    
    End Sub
    
    
    Note that I had the SetTabStopsInListbox procedure in a BAS module. I already gave that to you above.

    And now, when running this little test program, you get:

    Name:  Image2.gif
Views: 9135
Size:  9.4 KB

    Now, I haven't tried setting horizontal tab stops in Krool's ListBox, but I'm thinking it's going to work just fine. Both the VB6 ListBox and Krool's ListBox are just a more fundamental subclassed ListBox that's part of the Windows OS.

    Best Of Luck,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  16. #16
    Lively Member Mahdi Jazini's Avatar
    Join Date
    Feb 2014
    Location
    Iran / Tehran
    Posts
    89

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    Quote Originally Posted by Elroy View Post
    Started a project and then put a List1 listbox on it:

    In IDE design mode:

    Name:  Image1.gif
Views: 8547
Size:  9.5 KB

    And then, the code I placed in the form:

    Code:
    
    Option Explicit
    
    Private Sub Form_Load()
        Dim cols(1 To 3) As Long
    
        cols(1) = 25
        cols(2) = 70
        cols(3) = 100
    
        SetTabStopsInListbox List1, cols()
    
    
        List1.AddItem "asdf" & vbTab & "1234124" & vbTab & "zxcv" & vbTab & "piou"
        List1.AddItem "qwer" & vbTab & "1234124" & vbTab & "zxcv" & vbTab & "piou"
        List1.AddItem "fghj" & vbTab & "1234124" & vbTab & "zxcv" & vbTab & "piou"
        List1.AddItem "vbnm" & vbTab & "1234124" & vbTab & "zxcv" & vbTab & "piou"
    
    
    
    End Sub
    
    
    Note that I had the SetTabStopsInListbox procedure in a BAS module. I already gave that to you above.

    And now, when running this little test program, you get:

    Name:  Image2.gif
Views: 9135
Size:  9.4 KB

    Now, I haven't tried setting horizontal tab stops in Krool's ListBox, but I'm thinking it's going to work just fine. Both the VB6 ListBox and Krool's ListBox are just a more fundamental subclassed ListBox that's part of the Windows OS.

    Best Of Luck,
    Elroy
    Ahhhhh

    So the secret was (vbTab) Thank you

    Also thank you for using the SetTabStopsInListbox
    Last edited by Mahdi Jazini; Jan 8th, 2017 at 01:05 AM.

  17. #17
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    Quote Originally Posted by Elroy View Post
    Started a project and then put a List1 listbox on it:

    In IDE design mode:

    Name:  Image1.gif
Views: 8547
Size:  9.5 KB

    And then, the code I placed in the form:

    Code:
    
    Option Explicit
    
    Private Sub Form_Load()
        Dim cols(1 To 3) As Long
    
        cols(1) = 25
        cols(2) = 70
        cols(3) = 100
    
        SetTabStopsInListbox List1, cols()
    
    
        List1.AddItem "asdf" & vbTab & "1234124" & vbTab & "zxcv" & vbTab & "piou"
        List1.AddItem "qwer" & vbTab & "1234124" & vbTab & "zxcv" & vbTab & "piou"
        List1.AddItem "fghj" & vbTab & "1234124" & vbTab & "zxcv" & vbTab & "piou"
        List1.AddItem "vbnm" & vbTab & "1234124" & vbTab & "zxcv" & vbTab & "piou"
    
    
    
    End Sub
    
    
    Note that I had the SetTabStopsInListbox procedure in a BAS module. I already gave that to you above.

    And now, when running this little test program, you get:

    Name:  Image2.gif
Views: 9135
Size:  9.4 KB

    Now, I haven't tried setting horizontal tab stops in Krool's ListBox, but I'm thinking it's going to work just fine. Both the VB6 ListBox and Krool's ListBox are just a more fundamental subclassed ListBox that's part of the Windows OS.

    Best Of Luck,
    Elroy
    can fixed?
    Attached Images Attached Images  
    Last edited by xxdoc123; Apr 24th, 2019 at 08:58 PM.

  18. #18
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)

    something like this:

    Code:
        Dim cols(0 To 3) As Long    
        cols(0) = 50 'or whatever value big enough for your first (0th) column.  Experiment
        cols(1) = 300
        cols(2) = 100
        cols(3) = 100
    EDIT: Next time, start your own thread and put a link to an older one...because this one had already been marked RESOLVED, fewer people will look at it.
    Last edited by SamOscarBrown; Apr 25th, 2019 at 06:30 AM.

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