Microsoft KB Archive/822487

= BUG: The column width of a ListView control is not preserved when you re-create the handle of the control in Visual Basic .NET and in Visual C# .NET =

Article ID: 822487

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 Microsoft Windows Form with a ListView control. You add a manifest file (a file with a .manifest extension) that loads Microsoft Windows Common Controls 6.0 to your application. When you resize the column in the ListView control and then you re-create the handle of the control at run time, the column width is not preserved.



CAUSE
The ListView control receives the HDN_ENDTRACK header control notification handler after you drag the column divider. The ListView control then sends the LVM_GETCOLUMNWIDTH message in the WM_NOTIFY message to obtain the updated column width from the parent window. However, Windows Common Controls 6.0 returns the previous width of the column. Therefore, the width of the column is not preserved when you re-create the handle of the ListView control.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 In Microsoft Visual Studio .NET, start a new Windows application by using Microsoft Visual Basic .NET or Microsoft Visual C# .NET.

By default, Form1 is created. Add a ListView control to Form1. Right-click ListView1, and then click Properties. In the Properties dialog box, set the View property to Details. Click the Columns property, and then click the ellipses button (...). In the ColumnHeader Collection Editor, click Add, and then click OK.

ColumnHeader1 is added to the ColumnHeader Collection Editor.</li> Add a Button control to Form1.</li>  Add the following code to the Button1_Click event handler.

Visual Basic .NET Code 'Set the SortOrder of the ListView control. 'This re-creates the handle of the control. If ListView1.Sorting = SortOrder.Ascending Then ListView1.Sorting = SortOrder.Descending Else ListView1.Sorting = SortOrder.Ascending End If Visual C# .NET Code //Set the SortOrder of the ListView control. //This recreates the handle of the control. if (this.listView1.Sorting ==SortOrder.Ascending ) this.listView1.Sorting =SortOrder.Descending; else this.listView1.Sorting =SortOrder.Ascending; </li> In Solution Explorer, right-click the AssemblyInfo.vb file, and then click Open.</li> Add the &quot;XP themes&quot; string to the AssemblyTitle attribute of the assembly.</li> Add the &quot;Load Common Controls 6.0&quot; string to the AssemblyDescription attribute of the assembly.</li> Replace the &quot;1.0.*&quot; string with &quot;1.0.0.0&quot; in the AssemblyVersion attribute of the assembly.</li> On the Build menu, click Build Solution.</li> Move to the bin folder in your WindowsApplication1 project folder.</li> Create a new text document file in the folder that contains the .exe file.</li> Rename the text file .exe.manifest.

Note Replace  with the name of the .exe file.</li> Click Yes in the Rename dialog box.</li>  Open the manifest file in Notepad, and then paste the following code: <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?> <assembly xmlns=&quot;urn:schemas-microsoft-com:asm.v1&quot; manifestVersion=&quot;1.0&quot;> <assemblyIdentity version=&quot;1.0.0.0&quot; processorArchitecture=&quot;X86&quot; name=&quot;XP themes&quot; type=&quot;win32&quot; /> load Common Controls 6.0 <dependentAssembly> <assemblyIdentity type=&quot;win32&quot; name=&quot;Microsoft.Windows.Common-Controls&quot; version=&quot;6.0.0.0&quot; processorArchitecture=&quot;X86&quot; publicKeyToken=&quot;6595b64144ccf1df&quot; language=&quot;*&quot; /> </dependentAssembly> </li> Save the file, and then close the file.</li> On the Debug menu, click Start.</li> Resize the column of the ListView1 control.</li> <li>Click Button1.

The width of the column is not preserved. The column width is restored to its original value.</li></ol>

<div class="references_section">