JKP Application Development Services.

                    Microsoft Office Application Development

How It Works

Up • UserForm Setup • How It Works • Module Code & Conclusion

•  •

Search Zoeken

WWW
This site

Go to Ga Naar
Home
Up

Donate Donaties
Did you find something helpful on my site? Consider a donation!
Heeft u iets gevonden waar u wat aan had? Overweeg dan een donatie!

 

Showing An Array On A Form; Autosizing ColumnWidths Of A ListBox

How The Resize Works

Various people have devised a trick to calculate the column widths. Some use constants, which which the number of characters to be displayed is multiplied. This trick doesn't work reliably since screen resolution and Font may affect this.
The best method I know of is by using a (hidden) label with its AutoSize property set to True. This label must have the same Font characteristics as the ListBox. After changing the Caption of the Label, one can read it's width to fetch the size needed for the text.

The trick to make the resizing work lies in the Function SetWidths behind the userform (as shown on the previous page). I pass an array of character counts to the function (containing the maximum # of characters for each column to be shown in the listbox). Then for each column I change the caption of the label to an equal amount of characters as the value in the array. I use the same character, since the Font for the label is proportional. Thus, the letter used will determine what width the label gets.
Then I read the label's width and string that value together to form the ColumnWidths string (widths delimited by a ;).

The tricky part are the properties of the label. Set the WordWrap to False and the AutSize to True to make this work.

The end results looks like this:

Great, isn't it?

<< >>

Comments

Add a comment too!!!

Please enter your name (required, will be shown):

Your E-Mail address (optional; will not be shown, nor be used to send you unsolicited information):

Your comments on this page (will be shown):

 

    Subscribe in a readerpowered by longhead.com

Use the contact page to issue questions or comments about this website.
Copyright © 2003-2008 JKP Application Development Services