-
(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
-
1 Attachment(s)
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.
-
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
It's as simple as setting the Columns property to whatever value suits.
-
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.
-
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.
-
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 :)
-
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
@Pradeep:
look at the link I posted - it's the original. ;)
-
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. :)
-
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.
-
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?
-
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").
Regards.
-
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
Quote:
Originally Posted by RhinoBull
We may agree or disagree - who cares?
Exactly ;)
-
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
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)
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
Quote:
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)
I don't know but maybe this will help.
-
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".
Thank you
-
1 Attachment(s)
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
Are you willing to use a fixed width font like this one?
-
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
Quote:
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
-
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
Quote:
Originally Posted by
MartinLiss
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
-
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
-
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
Quote:
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
http://www.vbforums.com/showthread.p...mmon-controls)
last update of the ocx that @krool sent me:
http://krool.mooo.com/Data/VBForums/...BCCR13.OCX.zip
-
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
Quote:
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) !!!
Call ListBox2.AddItem(CStr(OBJRS("Summary")), 1)
-
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
-
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
Quote:
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 :D
-
2 Attachment(s)
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:
Attachment 143909
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:
Attachment 143911
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
-
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
Quote:
Originally Posted by
Elroy
Started a project and then put a List1 listbox on it:
In IDE design mode:
Attachment 143909
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:
Attachment 143911
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) :D Thank you :wave:
Also thank you for using the SetTabStopsInListbox :)
-
1 Attachment(s)
Re: (VB6) How can I have a MultiColumn ListBox? (Emergency)
Quote:
Originally Posted by
Elroy
Started a project and then put a List1 listbox on it:
In IDE design mode:
Attachment 143909
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:
Attachment 143911
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?
-
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.