Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 30th, 2004, 05:10 AM
Authorized User
 
Join Date: Mar 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Adding data into multi-column listbox

Hi guys

How do I add data into a multi-column listbox.
I have four columns in my listbox.
These match the contents of a select statement.
Do I have to put the results of my select statement into a multi-dimensional array first to reference it so that I can put the data into the listbox.
How do I reference a particular row, i.e

if my select statement returns 3 rows each with 4 columns

How do I set the first record in the listbox, i.e. row 1 column 1?

Do I use the AddItem method?

Many thanks in advance for any advice you can give

Cheers

Ciaran
 
Old March 30th, 2004, 09:58 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

You shouldn't have to use the AddItem if your listbox's rowsource is being filled by a query. Set the listbox's control source type to TABLE/QUERY and set its rowsource equal to your SELECT statement. To get the columns, set its Column Count property to 4. Set the bound column to the column that has the data you'll work with (1, 2, 3, or 4). Set the List Width property of the dropdown, e.g. 1;1;2;1. Set the listbox total width to the sum of the list width, in my example 1+1+2+1 = 5 (if you set it to Auto, for some reason it won't work).

You can reference items on your list, but note the inconsistency. To reference columns in your property dialog box, columns and rows start at 1 and 1 (e.g. bound column = 1, not 0). But in VBA code, column and width numbers (array) start at 0 and 0 (e.g. Me.MyListBox.Column(0,0)).



Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old March 30th, 2004, 10:16 AM
Authorized User
 
Join Date: Mar 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Greg

Thanks for your help.
I posted another topic relating to creating a scrollbar on the listbox because my last column exceeds the display area so I'd like to be able to scroll across and see the full contents of the listbox.

Do you know how I can achieve this?

Thanks

Ciaran
 
Old March 30th, 2004, 10:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Are you saying that your list width settings are something like 1;1;2;12 and that you can't possibly fit 12" on your monitor for column 4?

If this is the case, consider what is in column 4. Ideally the columns of a listbox (or combobox) should contain "just the facts, ma'am" (to quote Dragnet). If you find yourself adding a lengthy description field to your listbox's column 4, then in a word... DON'T. Instead, have the lengthy description appear in a memo field on your form AFTER you select your item. If column 4 is not a description but just a simple item (two or three words) but just plain too long, consider reducing the contents of column 4 so that they're shorter in length.

I know neither solves the problem, but there is no wordwrap in listboxes. And honestly, it wouldn't look good anyway.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old March 30th, 2004, 10:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

have you thought about using a listview control instead of the listbox? You may find this to be more able to do what you need it to do and would be my first choice.

Larry Asher
 
Old March 31st, 2004, 05:07 AM
Authorized User
 
Join Date: Mar 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi guys

Found a workaround, I just increased the last column width so that the total column widths are greater than the width of the listbox.

Cheers for the replies

Ciaran





Similar Threads
Thread Thread Starter Forum Replies Last Post
Add multi column data to listbox BradLee31 VB How-To 4 April 29th, 2008 07:48 AM
Multi Colum Listbox JAdkins Classic ASP Basics 3 July 9th, 2007 01:40 AM
SOS!How to realize multi-column asp.net ListBox? xewei VS.NET 2002/2003 2 June 3rd, 2007 09:24 PM
multi column listbox or combolist in VS 2005 alexdcosta ASP.NET 2.0 Basics 2 June 23rd, 2006 11:20 AM
multi-colmumn listbox e4thenf4 Beginning VB 6 0 September 7th, 2004 01:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.