Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox width value unchanged after form resize

Status
Not open for further replies.

NSNewey

Programmer
Jun 29, 2005
125
0
0
GB
Hi

I want to resize some columns in a listBox in code.
The form is set to sizable and the listBox anchor settings are such that the listbox grows with the form.

There are three columns, two of which I want to remain as fixed widths and one should grow when the listbox does. So the simple calculation for the (growing) column width is...
ListBox.Width minus total width of fixed columns.

My problem is that the result of listbox.width remains the same, even after resizing the form. The listbox is visibly larger but calling the width property in VBA always gives the width of the listbox as designed.

Is there another way to get the actual width of the listbox once the user has resized it?

Thanks

Neil
 
I have a thought...
By chance are your fixed width columns the first 2?

If so just define their widths, the third should always be the remainder.

On the otherhand, my instincts are telling me you can't resize controls past the On open event... But maybe I missed something in the newer versions.
 
How are ya NSNewey . . .

You need to set both the [blue]Column Widths[/blue] & [blue]Width[/blue] properties. [blue]Width[/blue] should be the total of [blue]Column Widths[/blue]. Also ... the values should be entered in [blue]Twips[/blue] ... where 1 inch = 1440 twips.

So if I wanted the [blue]Column Widths[/blue] to be 0.5;1;2 inches for a total 3.5 inches I'd have:
Code:
[blue]   Me.[B][I]ListboxName[/I][/B].ColumnWidths = "720;1440;2880"
   Me.[B][I]ListboxName[/I][/B].Width = 5040[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I may not have explained the problem properly...
I know how to set the column widths in code, the problem is that when the user resizes the form, the listbox grows due to the anchor settings (stretch down and accross). I want the first (left hand) column to grow as the list does. The other column widths can remain the same so the twips value for the first column must be the lists width (not it's bigger due to resize) minus the width of the other columns.

The problem is that querying the list width in code always returns the same value even after it's been resized by the user. It always returns the size it is in design view and not the actual new size after it's grown.

Any help with this please?
 
NSNewey . . .

I see. Doesn't appear it can be done. Out of curiosity what version access?

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 

Version 2007.

Now have a work around using the forms WindowWidth property whos value does change on resize.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top