Possible bugs in CListView

  • Todor Totev

    Todor Totev - 2009-02-21

    First of all, I am a total newbie to Windows GUI programming and Win32++ so maybe I am doing something wrong.

    1. CListView::InsertColumn(int iCol, LPCTSTR pszColumnHeading, ....)

    When using this overload, the insterted column is empty (no title etc). The problem seems related to the fact that the LVCOLUMN.mask is set to 0. I fixed it in this way:

        inline int CListView::InsertColumn( int iCol, LPCTSTR pszColumnHeading, int iFormat /*= LVCFMT_LEFT*/,
                            int iWidth /*= -1*/, int iSubItem /*= -1*/ )
        // Inserts a new column in a list-view control.
            lvc.iOrder = iCol;
            lvc.pszText = (LPTSTR)pszColumnHeading;
        lvc.fmt = iFormat;
        if (iWidth!=-1)
          lvc.mask |= LVCF_WIDTH;
              lvc.cx = iWidth;
        if (iSubItem!=-1)
          lvc.mask |= LVCF_SUBITEM;
              lvc.cx = iSubItem;
            return ListView_InsertColumn( m_hWnd, iCol, &lvc );

    2.ClistView::InsertItem( int iItem, LPCTSTR pszText ) does not insert the item. The problem seems to be that the function calls  ListView_SetItem. When I change it to ListView_InsertItem, it works. Note that the other overload uses LV_SetItem too.

    Hope this helps!

    • David

      David - 2009-02-22


      Thanks for bringing this to my attention.  There are indeed bugs in the CListView::InsertColumn and CListView::InsertItem as you describe.

      I've implemented fixes along the lines you suggested. They will be available in the next release of Win32++, or you can use Tortoise SVN to download a pre-release version with these fixes already incorporated.

      Best regards,

      • Robert Johnson

        Robert Johnson - 2009-06-04

        I found another bug in the CListView.  The GetItemData method should be as follows:

            inline DWORD_PTR CListView::GetItemData( int iItem ) const
            // Retrieves the value(lParam) specific to the item.
                LVITEM lvi = {0};
                lvi.iItem = iItem;
                lvi.mask = LVIF_PARAM;
                ListView_GetItem(m_hWnd, &lvi);
                return lvi.lParam;  // need to return the lParam


    • David

      David - 2009-06-05

      Hi Robert,
      thanks once again.  I've submitted a fix for this one.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks