Article ID: 151897 - Last Review: November 21, 2006 - Revision: 2.1 FIX: CListCtrl::InsertColumn() Causes Column Data to ShiftThis article was previously published under Q151897 On This PageSYMPTOMS
After adding items to a CListCtrl, if you call InsertColumn() to add
additional columns, column data starting from the second column will be
shifted right. For example, if you initially create two columns and add
your items, adding a third column will cause the data from the second
column to disappear and reappear in the third column. You may need to force
a repaint (minimize the window and restore it) to see the changes.
CAUSE
This is a bug in the Listview control. Sending an LVM_INSERTCOLUMN after
data has already been inserted, causes this problem.
RESOLUTION
There are several ways to work around this problem:
Method #1Use LPSTR_TEXTCALLBACK in the call to InsertItem(). This will cause a notification LVN_GETDISPINFO to be sent to the parent of the CListCtrl each time the text for each item is needed. The handler for this notification will then fill in the appropriate text for each item.Method #2Create all the columns up front before adding any items. You can hide columns by setting their initial width to zero in the call to InsertColumn(). To show columns, you can call SetColumnWidth() or SetColumn(). The only drawback to this method is that the user can still resize the column by dragging in the header control.Method #3Reset the contents of the CListCtrl via DeleteAllItems() and add all column data again after calling InsertColumn().STATUS
Microsoft has confirmed this to be a problem in the Microsoft products
listed at the beginning of this article. This bug has been fixed in
COMCTL32.DLL which as been released with Microsoft Windows NT 4.0 and
Microsoft Internet Explorer 3.01.
MORE INFORMATIONSample CodeMethod #1Method #2APPLIES TO
| Article Translations
|

Back to the top
