BUG: Problem with ListView's ColumnHeader Width PropertyLast reviewed: January 29, 1998Article ID: Q179988 |
The information in this article applies to:
SYMPTOMSWhen you programmatically set the Width of a ColumnHeader, the width of the column may actually appear larger than you expect. This presents a problem when you attempt to save the ColumnHeader Width settings so that you can restore them at a later time.
CAUSEInternally, the Width of a ColumnHeader is padded with some predetermined constant when it is changed programmatically. This padding is not in effect if the Width of the ColumnHeader is changed through the user interface.
RESOLUTIONTo work around this problem, you can set or return a ColumnHeader Width using the SendMessage API function with the LVM_SETCOLUMNWIDTH or LVM_GETCOLUMNWIDTH messages. The constant and function declarations are as follows:
Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _ ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _ ByVal lParam As Long) As Long Const LVM_FIRST = &H1000 Const LVM_GETCOLUMNWIDTH = LVM_FIRST + 29 Const LVM_SETCOLUMNWIDTH = LVM_FIRST + 30To set the Width of a Columnheader using the message LVM_SETCOLUMNWIDTH, you provide the index of the column (starting with 0) as the wParam and the new width as the lParam. For example, the following statement sets the width of the second column (index 1) of ListView1 to 150:
SendMessage ListView1.hWnd, LVM_SETCOLUMNWIDTH, 1, 150To retrieve the Width of a Columnheader using the message LVM_GETCOLUMNWIDTH, you provide the index of the column (starting with 0) as the wParam. The lParam is unused and should be set to 0. For example, the following statement returns the width of the second column (index 1) of ListView1:
Dim LVWidth as Long LVWidth = SendMessage (ListView1.hWnd, LVM_GETCOLUMNWIDTH, 1, 0) STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATION
Steps to Reproduce Behavior
|
Additional query words: list view comctl32 column width
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |