Make Listview Column width equal listbox item length

G

Gerry Viator

Hi all,

I would like to make a listview column width to fit the width of the largest
item length from a listbox?
Do I have to convert to pixcels? How?

Dim o As Object
Dim ItemSz As Integer
For Each o In ListEntries.Items
If o.length > ItemSz Then
ItemSz = o.length
End If
Next

Mainlistview.Columns.Add("Col1", ItemSz, HorizontalAlignment.Left)

thanks
Gerry
 
R

Rhett Gong [MSFT]

Hi Gerry,
From your description, you would like to adjust the columnheader to
fit he width of the largest item length.

To adjust the width of the longest item in the column, set the Width
property to -1. To autosize to the width of the column heading, set
the Width property to -2. In this issue, you can add the following
line "ColumnHeader1.Width = -1" to achieve your goal.

thanks,
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no
rights.
Please reply to newsgroups only. Thanks.
 
G

Gerry Viator

Thanks for your help,

I tried this and it doesn't work

Mainlistview.Columns.Add(New ColumnHeader)
Mainlistview.Columns(0).Text = "Value1"
Mainlistview.Columns(0).Width = -1
Mainlistview.Items.Add("This will Auto size the Width")

thanks
Gerry
 
J

John Vottero

Setting the width to -1 means "Look through the list and find the widest
item and set the width to that". The width isn't adjusted every time an
item is added so you have to add the items before you set the width to -1.

Gerry Viator said:
Thanks for your help,

I tried this and it doesn't work

Mainlistview.Columns.Add(New ColumnHeader)
Mainlistview.Columns(0).Text = "Value1"
Mainlistview.Columns(0).Width = -1
Mainlistview.Items.Add("This will Auto size the Width")

thanks
Gerry



Rhett Gong said:
Hi Gerry,
From your description, you would like to adjust the columnheader to
fit he width of the largest item length.

To adjust the width of the longest item in the column, set the Width
property to -1. To autosize to the width of the column heading, set
the Width property to -2. In this issue, you can add the following
line "ColumnHeader1.Width = -1" to achieve your goal.

thanks,
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no
rights.
Please reply to newsgroups only. Thanks.
 
G

Gerry Viator

thanks

Gerry


John Vottero said:
Setting the width to -1 means "Look through the list and find the widest
item and set the width to that". The width isn't adjusted every time an
item is added so you have to add the items before you set the width to -1.

Gerry Viator said:
Thanks for your help,

I tried this and it doesn't work

Mainlistview.Columns.Add(New ColumnHeader)
Mainlistview.Columns(0).Text = "Value1"
Mainlistview.Columns(0).Width = -1
Mainlistview.Items.Add("This will Auto size the Width")

thanks
Gerry



Rhett Gong said:
Hi Gerry,
From your description, you would like to adjust the columnheader to
fit he width of the largest item length.

To adjust the width of the longest item in the column, set the Width
property to -1. To autosize to the width of the column heading, set
the Width property to -2. In this issue, you can add the following
line "ColumnHeader1.Width = -1" to achieve your goal.

thanks,
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no
rights.
Please reply to newsgroups only. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top