Link to home
Start Free TrialLog in
Avatar of sternocera
sternocera

asked on

MFC: Displaying a CListView

I've added a CListView derived class to my project. The ListView displays, which is evident from the fact that if I drag my mouse across the view a "selection box" appears, which is characteristic of CListView derived classes.

Here is my OnInitialUpdate():
void CMyListView::OnInitialUpdate()
{
   CListView::OnInitialUpdate();

   // this code only works for a report-mode list view
   ASSERT(GetStyle() & LVS_REPORT);

   // Gain a reference to the list control itself
   CListCtrl& theCtrl = GetListCtrl();

   // Insert a column. This override is the most convenient.
   theCtrl.InsertColumn(0, _T("Player Name"), LVCFMT_LEFT);

   // The other InsertColumn() override requires an initialized
   // LVCOLUMN structure.
   LVCOLUMN col;
   col.mask = LVCF_FMT | LVCF_TEXT;
   col.pszText = _T("Jersey Number");
   col.fmt = LVCFMT_LEFT;
   theCtrl.InsertColumn(1, &col);

   // Set reasonable widths for our columns
   theCtrl.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
   theCtrl.SetColumnWidth(1, LVSCW_AUTOSIZE_USEHEADER);
}

This is a little peice of sample code from MSDN. I feel that I should see a populated CListView. However, I do not. The CListView derived class remains totally empty.

Your help is much appreciated, as always.
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

That adds the columns - there are no entries in any columns as far as I see.
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sternocera
sternocera

ASKER

Andy,

I see. Thanks a lot,
Sternocera