Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Debug assertion failed with CListCtrl...

40 views
Skip to first unread message

Erik

unread,
Sep 23, 2003, 3:25:31 PM9/23/03
to
In an SDI application I am creating I want to create a
listview in my child window (not a dialog), much like
Windows Explorer. I create an array of filenames in
OnNewDocument in my Document class. Then, in my View
class, I want to create a listview with just one column
containing these strings. My code is as follows:

// NOTES:
// m_documentList is a member variable of the view class
// pDoc->m_files is an array of CStrings

CArchieDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

// get the size of the view window
CRect rect;
this->GetClientRect( &rect );

// create list view
m_documentList.Create( WS_VISIBLE | WS_CHILD | WS_BORDER |
LVS_REPORT | LVS_SINGLESEL,
rect, this, IDC_DOCLIST );

// insert column
LV_COLUMN col;
col.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | VCF_SUBITEM;
col.fmt = LVCFMT_LEFT;
col.cx = 150;

col.iSubItem = 0;
col.pszText = "Filename";
m_documentList.InsertColumn( 0, &col );

// insert rows
for ( int n = 0; n < pDoc->m_files.GetSize(); n++ )
{
m_documentList.InsertItem( n, pDoc->m_files.GetAt( n ));
}

I have this code in a member function CreateDocumentList()
in my view class. When I call this function in OnDraw() I
get a debug assertion failure. I tracked it to the call to
m_documentList.Create(), which is pretty obvious.

What can I do to get it right? I think the pointer to the
owner of the listview is not correct, but that's only
guessing, and I dont know how to fix it. Any suggestions??

regards,
Erik

Kobi Ben Tzvi

unread,
Sep 23, 2003, 6:46:41 PM9/23/03
to
Erik,

> I have this code in a member function CreateDocumentList()
> in my view class. When I call this function in OnDraw() I
> get a debug assertion failure. I tracked it to the call to
> m_documentList.Create(), which is pretty obvious.

> m_documentList.Create( WS_VISIBLE | WS_CHILD | WS_BORDER |

Are you saying that above line is called each time OnDraw is executed ? If
yes, this is wrong and MFC ensures that you call "m_documentList.Create"
only once, thus the assert failure(OnDraw is called each time you need to
redraw your view).

Make sure you call "m_documentList.Create" just once.

--
Regards,
Kobi Ben Tzvi


"Erik" <er...@thesixthhouse.nl> wrote in message
news:07c801c38208$73e877f0$a101...@phx.gbl...

0 new messages