Vba listbox gridlines

ListBox and displaying data in grid-like format

ListBox and displaying data in grid-like format

Guest [visitor]
[OP]
26 Jul 01 12:23
In VBA there is a feature in listbox that allows you to have multiple columns. What I mean by this is to display data that needs to be in grid like format you can use a listbox and set columncount to the number of Columns you need. You can also set ListBox1.List[irow, icolumn]= "some text" I cant seem to do this in VB and I must display data in a row/Column format. Any ideas?
Thanks for your help.

RE: ListBox and displaying data in grid-like format

MarkSweetland [MIS] 26 Jul 01 13:20
You can simulate a multicolumn listbox with an MSFlexGrid control:


Private Sub Form_Load[]
fg.Clear
fg.Rows = 2
' Hide the gridlines
fg.GridLines = flexGridNone
' Show only vertical scrollbar
fg.ScrollBars = flexScrollBarVertical
fg.TextMatrix[0, 0] = "Row0Col0"
fg.TextMatrix[0, 1] = "Row0Col1"
fg.TextMatrix[0, 2] = "Row0Col2"
fg.TextMatrix[0, 3] = "Row0Col3"
fg.TextMatrix[1, 0] = "Row1Col0"
fg.TextMatrix[1, 1] = "Row1Col1"
fg.TextMatrix[1, 2] = "Row1Col2"
fg.TextMatrix[1, 3] = "Row1Col3"
'space columns evenly [or set accordingly]
For I = 0 To fg.Cols - 1
fg.ColWidth[I] = fg.Width / fg.Cols
Next
End Sub

Private Sub fg_Click[]
' get first column text
MsgBox [fg.TextMatrix[fg.Row, 0]]
End Sub




Mark

RE: ListBox and displaying data in grid-like format

MikeCox [Programmer] 26 Jul 01 15:40
If you still need to use a listbox, you can do this:

Make several list boxes [the same number as the number of columns in your grid], and place them on the form so that each one just covers up the scrollbar section of the listbox to its left, so that the only scrollbar that will be visible is the one on the far right.Then add your data to the appropriate listbox just like it's a column in a grid.After that, you just have to make all listboxes "act" like one control:

'assumes only 2 listboxes [use array to make easier]
Private CommonTop as Long 'all listbox's TopIndex
Private CommonIndex as Long 'all listbox's ListIndex

Private Sub List1_MouseDown[Button as Integer, etc...]
CommonIndex = List1.ListIndex
SyncLists
End Sub

Private Sub List2_MouseDown[Button as Integer, etc...]
CommonIndex = List2.ListIndex
SyncLists
End Sub

Private Sub List1_Scroll[]
CommonTop = List1.TopIndex
SyncLists
End Sub

Private Sub List2_Scroll[]
CommonTop = List2.TopIndex
SyncLists
End Sub


Private Sub SyncLists
List1.ListIndex = CommonIndex
List2.ListIndex = CommonIndex

List1.TopIndex = CommonTop
List2.TopIndex = CommonTop
End Sub

I've heard this tecnique called "poor man's tables", but it can be really effective.The only downfall is you'll see a big performance hit with more than about 6 columns.

If you're dealing with data that's going to be the same string length, you can use vbTab between the values and only use one listbox, but if the tab character is too big [i.e. it tabs over too far], you'll have to use API to set the tab width.

Good luck!

-Mike

Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.

RE: ListBox and displaying data in grid-like format

mgriffith [MIS] 25 Jul 02 11:51
i realize this thread has been inactive for 364 days, but i figured i'd ask my question anyway because maybe you found a solution to your problem...

i'm required to write an app in vb6 for maintenace reasons...i'm stuck with the stupid listbox control that i can't seem to do anything constructive with...does anyone know of a 3rd party listbox control [that is free or very inexpensive] that will allow me to store an object as a listitem, and then the object uses some type of tostring method to display the text for the item....or even just have a listitem.text and listitem.value property?i know that vb.net and c# both support the object thing, but i'm not allowed to write windows apps in .net yet because there's like 300 computers that still need the framework installed, and quite a few of them will be using the app

thanks in advance for any help

mike griffith
----------------------------

RE: ListBox and displaying data in grid-like format

johnwm [Programmer] 25 Jul 02 12:33
Try looking at the Microsoft Listview control. Its in Microsoft Windows Common Controls 6.0

Load one into a form and right click for properties page. Set View to lvwReport and then you can add extra columns as required, either at design time or in code.

Its all in the Help file under Listview

Let me know if this helps

RE: ListBox and displaying data in grid-like format

mgriffith [MIS] 25 Jul 02 16:17
excellent excellent...you get a star

i actually had decided to turn this part into a web app [so i can use vb.net -- webforms controls are pretty versatile] and just use a webbrowser control, but i think i might keep it in a vb interface now because listview seems to be not too shabby as far as columns support goes

thank you very much

mike griffith
----------------------------

RE: ListBox and displaying data in grid-like format

MikeCox [Programmer] 26 Jul 01 15:40
If you still need to use a listbox, you can do this:

Make several list boxes [the same number as the number of columns in your grid], and place them on the form so that each one just covers up the scrollbar section of the listbox to its left, so that the only scrollbar that will be visible is the one on the far right.Then add your data to the appropriate listbox just like it's a column in a grid.After that, you just have to make all listboxes "act" like one control:

'assumes only 2 listboxes [use array to make easier]
Private CommonTop as Long 'all listbox's TopIndex
Private CommonIndex as Long 'all listbox's ListIndex

Private Sub List1_MouseDown[Button as Integer, etc...]
CommonIndex = List1.ListIndex
SyncLists
End Sub

Private Sub List2_MouseDown[Button as Integer, etc...]
CommonIndex = List2.ListIndex
SyncLists
End Sub

Private Sub List1_Scroll[]
CommonTop = List1.TopIndex
SyncLists
End Sub

Private Sub List2_Scroll[]
CommonTop = List2.TopIndex
SyncLists
End Sub


Private Sub SyncLists
List1.ListIndex = CommonIndex
List2.ListIndex = CommonIndex

List1.TopIndex = CommonTop
List2.TopIndex = CommonTop
End Sub

I've heard this tecnique called "poor man's tables", but it can be really effective.The only downfall is you'll see a big performance hit with more than about 6 columns.

If you're dealing with data that's going to be the same string length, you can use vbTab between the values and only use one listbox, but if the tab character is too big [i.e. it tabs over too far], you'll have to use API to set the tab width.

Good luck!

-Mike

Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.

Video liên quan

Chủ Đề