Listbox Column Width

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I can't seem to find anything on this, so I'm hoping someone here can help.

I have a listbox with two columns. The 'divider' between the two columns is
set to the middle of the listbox. What I would like is that column 1 is only
as wide as the longest string in that column. Column 2 then takes up the
remaining space.

Currently there is a scrollbar for the listbox, but on some forms, I
wouldn't need it if I could get Column 1 to autosize. I don't want to
specify a number as the column width as I don't know how wide I'll need it
ahead of time. It depends on the data I'm pulling from a table and
displaying in the listbox.

Any suggestions are appreciated.

Thanks,
Jay
 
This can be done, but will be a little tricky. The only way to change the
column widths at run time is with VBA. That would be setting the
ColumnWidths property. Look in VBA Help for details on how to use it. To
make it adjust for different widths, you will need to determine how wide
column 1 needs to be based on the data you will be displaying. Then, you
will have to subtract that from the total width to determine how wide column
2 should be, then set the ColumnWidths property.
 
Thanks! I was afraid I'd have to get into VBA.

Allen's link helped, I just needed to play around with the code a bit.
 
Back
Top