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

column width in ListBox

P: n/a
Hi everyone,

I have a database table with first name and last name entries. I am
using a ListBox to show these values.

Now what I want is that the columns adjust their width automatically
based on the length of the longest name. Is there some way I can do
this rather than set the width manually. Maybe there is a better
control to show these values and allow the user to select multiple
values at a time?

Any ideas or suggestions?

Cheers,
Pankaj

Nov 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
de**********@gmail.com wrote:
Hi everyone,

I have a database table with first name and last name entries. I am
using a ListBox to show these values.

Now what I want is that the columns adjust their width automatically
based on the length of the longest name. Is there some way I can do
this rather than set the width manually. Maybe there is a better
control to show these values and allow the user to select multiple
values at a time?

Any ideas or suggestions?

Cheers,
Pankaj
Datasheets have the ability to resize but listbox/combobox are fixed width.

You might find something at http://www.lebans.com/. Search for Listbox
and also check out the table of contents for possible functions/classes
that will help you determine the width of the name.

Once you know the max size you'll then need to resize the columns via
VBA. Ex:
Me.ListBoxName.ColumnWidths = "0 in;0.75 in;2 in"
Me.ListBoxName.ColumnWidths = "0 cm;0.75 cm;2 cm"
You most likely will have to convert twips to inches or centimeters.

Nov 27 '06 #2

P: n/a
See:
http://www.lebans.com/listboxcolumnresize.htm
ListBoxColumnResize.zip is a Class that allows the user to resize the
ColumnWidths of a ListBox at Runtime.Also supports an Autosizing method for
the ColumnWidths.

Version 2.2 April 27/2002

Modified Columns AutoSizing method to work with both ListBox and Combo
controls.

Version 2.1 April 10/2002

BUG FIX! I thought I had cleaned this bug from all of my code but I missed
one instance. In Win9x this code will work 100% of the time:

If lngIC 0 Then But in WinNT or higher the GDI object handles are full
32 bit values so they can be represented by the VB as negative values. The
solution is to change the code to: If lngIC <0 Then

Version 2.0 April 9/2002

Added support for AUTOSIZING of ColumnWidths.
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.

<de**********@gmail.comwrote in message
news:11**********************@45g2000cws.googlegro ups.com...
Hi everyone,

I have a database table with first name and last name entries. I am
using a ListBox to show these values.

Now what I want is that the columns adjust their width automatically
based on the length of the longest name. Is there some way I can do
this rather than set the width manually. Maybe there is a better
control to show these values and allow the user to select multiple
values at a time?

Any ideas or suggestions?

Cheers,
Pankaj

Nov 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.