By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,654 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,654 IT Pros & Developers. It's quick & easy.

how to show the table in the list box

P: 24
Hello maybe you know how to show the table in the list box? for example I want to show this results in the list box:


vegetables fruits
Tomato apple
cucumber apricot
Apr 27 '07 #1
Share this Question
Share on Google+
6 Replies


SammyB
Expert 100+
P: 807
Hello maybe you know how to show the table in the list box? for example I want to show this results in the list box:


vegetables fruits
Tomato apple
cucumber apricot
What VB are you using? VBA(if so, which application), VB6, or VB.Net?

If you are using VB.Net, you might want to consider using a ListView control instead:
  1. Add a ListView control
  2. In the Design Mode, add two columns to the Columns property: Vegetables, Fruits
  3. In the form load event, you can load the rows:
Expand|Select|Wrap|Line Numbers
  1. ListView1.View = View.Details
  2. ListView1.Items.Add(New ListViewItem(New String() {"Tomato", "Apple"}))
  3. ListView1.Items.Add(New ListViewItem(New String() {"Cucumber", "Apricot"}))
HTH --Sam
Apr 27 '07 #2

P: 24
I use VB 6.0
Apr 27 '07 #3

SammyB
Expert 100+
P: 807
I use VB 6.0
Bummer! If I remember correctly, you'll have to do it yourself. In other words, you'll have to insert enough spaces so that it looks like you have columns. I also remember using multiple listboxes placed together so that they looked like a single multiple column listboxes. But coordinating selection/scrolling was a pain.

Maybe Killer will have some good suggestions when he arrives later this evening. I also be back to a VB6 machine in a couple of hours and I'll see if I still have any pseudo-column code.

Another thought: if you have Microsoft Office installed on your computer, then you should be able to add Microsoft Forms 2.0 ListBox to your form. Right-click on the toolbox and browse to \Windows\System32\FM20.dll, then add the ListBox to your project. With it you use the ColumnCount property. Here's some sample code, http://msdn2.microsoft.com/en-us/lib...ffice.11).aspx. I'll see if it works for VB6 in a couple of hours. HTH --Sam
Apr 27 '07 #4

SammyB
Expert 100+
P: 807
Forms 2.0 ListBox works!:
Expand|Select|Wrap|Line Numbers
  1.     Dim lstArray(3, 2) ' three rows, two columns
  2.     ListBox1.ColumnCount = 2
  3.     lstArray(0, 0) = "Vegetables"
  4.     lstArray(1, 0) = "Tomato"
  5.     lstArray(2, 0) = "Cucumber"
  6.     lstArray(0, 1) = "Fruits"
  7.     lstArray(1, 1) = "Apple"
  8.     lstArray(2, 1) = "Apricot"
  9.     ListBox1.List() = lstArray
But, it has an annoying "feature:" the ColumnHeads only works if the control is getting the data from a RowSource & even then it gets the data before the RowSource ie, I think it will only work for Excel. But, the workaround is to just use Label controls for the headers. HTH --Sam
Apr 27 '07 #5

P: 24
I undestood this way, but it was only example. Now I want to show two or more records of my access database in one list box. I wrote a code such as:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command4_Click()
  2. List1.Clear
  3. Set db = OpenDatabase("the path of my database")
  4. Set rec = db.OpenRecordset("SELECT * From asmenu_info WHERE asmenu_info.Vardas in ('Eglė','Regina');")
  5. While Not rec.EOF
  6.   List1.AddItem rec!ID
  7.   rec.MoveNext
  8. Wend
  9. rec.Close
  10. db.Close
  11. End Sub
With this code I can add only one record to my list. I want to show more than one record in the list box.
Apr 28 '07 #6

Expert 5K+
P: 8,434
As far as I can see, the only reason this would be limited to a single record is if your WHERE clause does so. The While loop should add the entire recodset to the listbox.
Apr 30 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.