Microsoft KB Archive/822489

= Text of a ListView item is changed when the Text property of the first subitem is set =

Article ID: 822489

Article Last Modified on 5/16/2007

-

APPLIES TO


 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition

-





SYMPTOMS
You have a ListView control in Details view and you add columns to the control. You add an item to the control, and then you set the Text property of the item. When you add a subitem to this item, and you then set the Text property of the first subitem in the ListViewSubItem Collection Editor dialog box, the text of the item in the first column of the ListView control is changed to the text of the subitem.

Note The first column in the ListView control displays the Text property of the items. All the other columns display the Text property of the subitems of the main item.



WORKAROUND
To work around the problem, add a subitem to the list item, and then set the Text property. To do this, follow these steps:
 * 1) Perform steps 1-10 in the &quot;Steps to Reproduce the Behavior&quot; section.
 * 2) In the ListViewSubItem Collection Editor dialog box, click Add.
 * 3) Set the Text property to SubItem1, and then click OK.
 * 4) In the ListViewItem Collection Editor dialog box, click OK.



STATUS
This behavior is by design.



Steps to Reproduce the Behavior

 * 1) Start Microsoft Visual Studio .NET.
 * 2) Create a new Windows Application project by using Visual Basic .NET or Visual C# .NET. By default, Form1 is created.
 * 3) Add a ListView control to Form1.
 * 4) Right-click ListView1, and then click Properties.
 * 5) In the Properties dialog box, set the View property to Details.
 * 6) Select the Columns property, and then click the ellipsis button (...).
 * 7) In the ColumnHeader Collection Editor dialog box, click Add three times, and then click OK.
 * 8) Select the Items property, and then click the ellipsis button (...).
 * 9) In the ListViewItem Collection Editor dialog box, click Add.
 * 10) Set the Text property of the ListView item to Item1.
 * 11) Select the SubItems property, and then click the ellipsis button (...).
 * 12) In the ListViewSubItem Collection Editor dialog box, set the Text property to Subitem1, and then click OK.
 * 13) In the ListViewItem Collection Editor dialog box, click OK.

In ListView1, the text in the first column is &quot;Subitem1&quot;. You expect the text in the first column to be &quot;Item1&quot; and you expect the text in the second column to be &quot;Subitem1&quot;.

