MFC CListView Problem with SetItem

I am using a CListView in an MFC SDI application. I am able to add columns using InsertColumn(LPLVCOLUMN) and able to set the item in column 1 with InsertItem(LPLVITEM) but when I try to add subitems to columns 2 and above using SetItem(LPLVITEM), the subitems do not display their text.

I am using Visual Studio 2008 Professional. When I try to add columns, items, and subitems to a List Control in a Dialog Box, SetItem works.

I am setting the style of the list view with a call to ModifyStyle(0,LVS_REPORT) so that it is in the report mode. All that appears in the list view is the column headings (successfully printed) and the item text for column 1. Columns 2 and above are blank.

Any help would be appreciated.


  • [color=Blue]Instead of SetItem use the following:
  • I've tried SetItemText too but that doesn't work either.

    I've tried it also using Visual C++ .NET 2003 and still am unable to write to subitems (columns 2 and above) with SetItem.

  • The solution was that I was setting the column headings in OnInitialUpdate and setting the subitems in OnUpdate. The call to the base class OnInitalUpdate was at the beginning of my code block so when the base class call called OnUpdate my columns weren't set up before trying to add subitems.

    The problems was fixed by moving the CListView::OnInitialUpdate call to the last statement of my code block in CMyListView::OnInitialUpdate

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!