469,631 Members | 1,847 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

Autosize Limits on ListView Column Sizes

Can anyone confirm whether or not there are any limits imposed on the widths
of autosized columns in a list-view. I've found that the autosizing appears
to have an upper limit, i.e. it will not expand beyond some (unknown)
maximum length. This applies to user-autosizing (double-clicking the
divider) and code-autosizing using LVSCW_AUTOSIZE.

For example, create a new project and place a ListView (VB5 version) and
CommandButton on a form and insert the following code:

Const LVM_SETCOLUMNWIDTH As Long = &H101E
Const LVM_SETEXTENDEDLISTVIEWSTYLE As Long = &H1036
Const LVS_EX_LABELTIP As Long = &H4000
Const LVSCW_AUTOSIZE As Long = &HFFFFFFFF
Const LVSCW_AUTOSIZE_USEHEADER As Long = &HFFFFFFFE

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) As Long

Private Sub Command1_Click()
Dim i As Long

Call ListView1.ListItems.Clear

For i = 0 To 100

With ListView1.ListItems.Add(, , String$(300, AscW(CStr(i))))
.SubItems(1) = String$(300, AscW(CStr(i)))
.SubItems(2) = String$(300, AscW(CStr(i)))
End With

Next

Call SendMessage(ListView1.hWnd, LVM_SETCOLUMNWIDTH, 1, ByVal
LVSCW_AUTOSIZE_USEHEADER)
Call SendMessage(ListView1.hWnd, LVM_SETCOLUMNWIDTH, 2, ByVal
LVSCW_AUTOSIZE)
End Sub

Private Sub Form_Load()
ListView1.View = lvwReport
Call ListView1.ColumnHeaders.Add(, , "Column 1")
Call ListView1.ColumnHeaders.Add(, , "Column 2")
Call ListView1.ColumnHeaders.Add(, , "Column 3")
Call SendMessage( _
ListView1.hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_LABELTIP, ByVal
LVS_EX_LABELTIP)
End Sub

I've noticed the following:

1. "Column 3" does not completely autosize, it stops short of the full range
of characters and also does not apply trailing ellipsis. The limit seems to
be 260 chars (259 chars + null terminator), however this only applies to
"drawing" the text since the tooltip indicates that the full text is
correctly stored in the list-view.
2. "Column 2" does not autosize to the header, LVSCW_AUTOSIZE_USEHEADER
seems to be working like LVSCW_AUTOSIZE here (note that it is not the last
column, hence it should really autosize to the column header).
3. Double-clicking the divider to the right of "Column 1" produces the same
results for "Column 1" as 1. does for "Column 3."

Is this behaviour intentional? I could understand the limits to autosizing
columns based on the fact that true autosizing could get crazy for columns
containing large amounts of text, however there's nothing documented in
MSDN. The clipped text seems like a drawing bug to me, maybe related to
using a MAX_PATH sized buffer for drawing?

--
Kevin Westhead
Nov 20 '05 #1
9 9880
"Kevin Westhead" <ke****@NOSPAM.i2DOTcoDOTuk> schrieb
Can anyone confirm whether or not there are any limits imposed on the
widths of autosized columns in a list-view. I've found that the
autosizing appears to have an upper limit, i.e. it will not expand
beyond some (unknown) maximum length. This applies to user-autosizing
(double-clicking the divider) and code-autosizing using
LVSCW_AUTOSIZE.

For example, create a new project and place a ListView (VB5 version)
and CommandButton on a form and insert the following code:


VB5 is dead. This is a group about VB.Net (see group name).
microsoft.public.vb.* deals with older verions.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
* "Armin Zingler" <az*******@freenet.de> scripsit:
Can anyone confirm whether or not there are any limits imposed on the
widths of autosized columns in a list-view. I've found that the
autosizing appears to have an upper limit, i.e. it will not expand
beyond some (unknown) maximum length. This applies to user-autosizing
(double-clicking the divider) and code-autosizing using
LVSCW_AUTOSIZE.

For example, create a new project and place a ListView (VB5 version)
and CommandButton on a form and insert the following code:


VB5 is dead.


Only in this group, but there are other groups where it's still alive
;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
> > VB5 is dead.

Only in this group, but there are other groups where it's still alive
;-).


And?
Nov 20 '05 #4
"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de...
VB5 is dead. This is a group about VB.Net (see group name).
microsoft.public.vb.* deals with older verions.


You're right (about the newsgroup), I absent mindedly posted to the wrong
group - sorry.

Having said that, a quick test with a WinForms list-view shows that the same
problem occurs, so it's most likely a problem with the underlying common
control rather than any language-specific issue.

--
Kevin Westhead
Nov 20 '05 #5
* "Cor Ligthert" <no**********@planet.nl> scripsit:
VB5 is dead.


Only in this group, but there are other groups where it's still alive
;-).


And?


.... nothing!

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #6
Hi Kevin,

I think you may try to take a look at the link below, is that what are you
looking for? If you still have any concern on this issue, please feel free
to post here.

SYMPTOMS
When you add long strings to a ListView control, all of the string is added
to the items collection, but the control can only display the first 259
characters of each item.

PRB: ListView Control Can Only Display 259 Characters per Column (321104)
http://support.microsoft.com/default...B;EN-US;321104

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #7
""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:4m**************@cpmsftngxa10.phx.gbl...
SYMPTOMS
When you add long strings to a ListView control, all of the string is added to the items collection, but the control can only display the first 259
characters of each item.

PRB: ListView Control Can Only Display 259 Characters per Column (321104)
http://support.microsoft.com/default...B;EN-US;321104

Thanks Peter.

Can you explain why this is by design, i.e. why does a limit exist for
displaying an item's text but there is no limit for the actual item text
stored with the item? Is it performance related? I take it then that the
autosizing algorithm uses the displayed string then?

--
Kevin Westhead
Nov 20 '05 #8
Hi Kevin,

Thank you for your response.
Why the length of the text of listview item is limited to 259 character is
because that the listview is design for display collection of objects like
files and not for general purpose control. So it is similar to the filename
length limitation in the windows file system's MAX_PATH.

Hope this helps.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #9
""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:OO**************@cpmsftngxa10.phx.gbl...
Why the length of the text of listview item is limited to 259 character is
because that the listview is design for display collection of objects like
files and not for general purpose control. So it is similar to the filename length limitation in the windows file system's MAX_PATH.

Okay, thanks. It seems like it would still be a good idea to use trailing
ellipsis when drawing the text for items that have text > 259 characters.

--
Kevin Westhead
Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by | last post: by
1 post views Thread by Cybertof | last post: by
12 posts views Thread by J L | last post: by
1 post views Thread by Duracel | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.