Microsoft KB Archive/321104

= ListView control can only display 259 characters per column =

Article ID: 321104

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Visual Basic 2005 Express Edition
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



This article was previously published under Q321104



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.



RESOLUTION
To display the full text of an item in the ListView control, you can populate a TextBox control with the selected value. For example, the following code populates a TextBox (TextBox1) with the text from the first item that is selected from the ListBox control (ListBox1): Private Sub ListView1_SelectedIndexChanged(ByVal sender _        As Object, ByVal e As System.EventArgs) _ Handles ListView1.SelectedIndexChanged Me.TextBox1.Text = ListView1.SelectedItems(0).Text End Sub



STATUS
This behavior is by design.



Steps to Reproduce the Behavior
 Follow these steps to create a new Visual Basic Windows Application:  Start Microsoft Visual Studio .NET or Microsoft Visual Basic 2005. On the File menu, point to New, and then click Project. In the New Project dialog box, click Visual Basic Projects under Project Types, and then click Windows Application under Templates. By default, Form1 is created.

Note In Visual Studio 2005, click Visual Basic under Project Types.  Drag a ListView control from the Windows Forms portion of the toolbox to Form1. By default, the control is named ListView1.</li>  Add the following code to the Load event of Form1: Dim MyColumn As ColumnHeader Dim MyListViewItem As ListViewItem Dim strSample As String

strSample = &quot;This is a long paragraph to demonstrate&quot; _ & &quot; the 259 character limitation of the ListView&quot; _ & &quot; control. Although the string is stored in its&quot; _ & &quot; entirety, the ListView control can only display&quot; _ & &quot; the first two hundred and fifty nine characters&quot; _ & &quot; of the string value. The ListBox control in&quot; _ & &quot; Visual Basic .NET offers an alternative in that&quot; _ & &quot; it now supports a horizontal scroll bar so that&quot; _ & &quot; the user can view all of the string when necessary.&quot;

' Create a column header for the data. MyColumn = New ColumnHeader MyColumn.Text = &quot;Sample&quot; Me.ListView1.Columns.Add(MyColumn)

' Create sample ListView data. MyListViewItem = New ListViewItem(strSample) Me.ListView1.Items.Add(MyListViewItem)

' Set view of ListView to Details. Me.ListView1.View = View.Details </li> Drag a Button control from the Windows Forms portion of the toolbox to Form1. By default, the control is named Button1.</li>  Add the following code to the Click event of Button1: Dim strText As String strText = ListView1.Items(0).Text MessageBox.Show(Len(strText) & &quot;: &quot; & strText) </li> Save the project.</li> On the Debug menu, click Start.</li> When the form appears, resize the ListView column header as far as possible. Notice that the text stops at a point after &quot;The Lis&quot; (of the sentence that begins &quot;The ListBox control&quot;) even though the column is wider than the text that is displayed.</li> Click Button1, and notice that the MessageBox returns the string length of 407 followed by the complete text.</li></ol>

Additional query words: limited to 259 character limitation

Keywords: kbvs2005swept kbvs2005applies kbctrl kblistview kbprb KB321104

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.