(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.
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
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.
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
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
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.
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
As I said, it works for me. By setting the Columns property it creates 'snaking' columns in the listbox which are populated vertically then horizontally, ie 'down then across' which is perfect for my purpose. Let's just agree to disagree shall we?
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
We may agree or disagree - who cares? The point is - what you (and original developer of that listbox) refer as "Column" isn't exactly column.
Column (by definition I guess) is data presented in the columnar (true vertical) way. Also, columns usually have column headers.
Columns in the "columnar" listbox are depending on the height of listbox so control is populated "horizontally" as soon as the "bottom" is reached...
How can anyone consider that a columns I have no idea (but I know that it "serves your purpose").
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer.
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
I have faced a problem with ListView.
The ListView doesn't have a "Right-to-Left" property, and I want it to be "Right to Left", because my language is Farsi.
I'm getting frustrated. Isn't there a good Multi-Column Listbox in VB6?
Thank you
Originally Posted by javad2000
Thank you everybody.
I found the listview and I also think it's the best choice.
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
That would help if I was a professional, but I'm not looking for API methods, I'm looking for an easy and clean way to show my multi-column data in a "List". So that the SelectionMode is "By Row".
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
Originally Posted by MartinLiss
Are you willing to use a fixed width font like this one?
Yes, and I know how to use this method to make Signle-column Listboxes appear in "Multi-column" view, but I don't know which Farsi font is a 'fixed-width font'. I will ask it from my persian freids.
If there is a better way to make "multi-column" listboxes, please let me know.
Thank you
Last edited by javad2000; Dec 21st, 2006 at 05:33 AM.
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.
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
Originally Posted by javad2000
I have faced a problem with ListView.
The ListView doesn't have a "Right-to-Left" property, and I want it to be "Right to Left", because my language is Farsi.
I'm getting frustrated. Isn't there a good Multi-Column Listbox in VB6?
Thank you
Hello Compatriot
In the following thread @krool designed an upgraded version of ListView that supports unicode. It's free and opensource
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
Originally Posted by Elroy
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) !!!
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.
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
Originally Posted by Elroy
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
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:
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.
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:
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.
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:
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?
Last edited by xxdoc123; Apr 24th, 2019 at 08:58 PM.
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.