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 (822487)



The information in this article applies to:

  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# .NET (2002)

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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. 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.
  2. Add a ListView control to Form1.
  3. Right-click ListView1, and then click Properties.
  4. In the Properties dialog box, set the View property to Details.
  5. Click the Columns property, and then click the ellipses button (...).
  6. In the ColumnHeader Collection Editor, click Add, and then click OK.

    ColumnHeader1 is added to the ColumnHeader Collection Editor.
  7. Add a Button control to Form1.
  8. 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; 
  9. In Solution Explorer, right-click the AssemblyInfo.vb file, and then click Open.
  10. Add the "XP themes" string to the AssemblyTitle attribute of the assembly.
  11. Add the "Load Common Controls 6.0" string to the AssemblyDescription attribute of the assembly.
  12. Replace the "1.0.*" string with "1.0.0.0" in the AssemblyVersion attribute of the assembly.
  13. On the Build menu, click Build Solution.
  14. Move to the bin folder in your WindowsApplication1 project folder.
  15. Create a new text document file in the folder that contains the .exe file.
  16. Rename the text file WindowsApplication1.exe.manifest.

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

    The width of the column is not preserved. The column width is restored to its original value.

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MinorLast Reviewed:2/3/2006
Keywords:kbvs2005swept kbvs2005doesnotapply kbvs2002sp1sweep kbCmnCtrls kbListView kbCtrl kbControl kbbug KB822487 kbAudDeveloper